Skip to content

modify_instance_metadata_defaults async

modify_instance_metadata_defaults(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    http_tokens: Optional[MetadataDefaultHttpTokensState] = None,
    http_put_response_hop_limit: Optional[BoxedInteger] = None,
    http_endpoint: Optional[DefaultInstanceMetadataEndpointState] = None,
    instance_metadata_tags: Optional[DefaultInstanceMetadataTagsState] = None,
    dry_run: Optional[Boolean] = None,
    http_tokens_enforced: Optional[DefaultHttpTokensEnforcedState] = None,
) -> ModifyInstanceMetadataDefaultsResult

Modifies the default instance metadata service (IMDS) settings at the account level in the specified Amazon Web Services Region.

To remove a parameter's account-level default setting, specify no-preference. If an account-level setting is cleared with no-preference, then the instance launch considers the other instance metadata settings. For more information, see Order of precedence for instance metadata options in the Amazon EC2 User Guide.

Parameters:

  • http_tokens (Optional[MetadataDefaultHttpTokensState], default: None ) –

    Indicates whether IMDSv2 is required.

    • optional – IMDSv2 is optional, which means that you can use either IMDSv2 or IMDSv1.

    • required – IMDSv2 is required, which means that IMDSv1 is disabled, and you must use IMDSv2.

  • http_put_response_hop_limit (Optional[BoxedInteger], default: None ) –

    The maximum number of hops that the metadata token can travel. To indicate no preference, specify -1.

    Possible values: Integers from 1 to 64, and -1 to indicate no preference

  • http_endpoint (Optional[DefaultInstanceMetadataEndpointState], default: None ) –

    Enables or disables the IMDS endpoint on an instance. When disabled, the instance metadata can't be accessed.

  • instance_metadata_tags (Optional[DefaultInstanceMetadataTagsState], default: None ) –

    Enables or disables access to an instance's tags from the instance metadata. For more information, see View tags for your EC2 instances using instance metadata in the Amazon EC2 User Guide.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the operation, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • http_tokens_enforced (Optional[DefaultHttpTokensEnforcedState], default: None ) –

    Specifies whether to enforce the requirement of IMDSv2 on an instance at the time of launch. When enforcement is enabled, the instance can't launch unless IMDSv2 (HttpTokens) is set to required. For more information, see Enforce IMDSv2 at the account level in the Amazon EC2 User Guide.

Raises:

Source code in docs_src/capo_ec2/_services/async_ec2.py
async def modify_instance_metadata_defaults(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    http_tokens: Optional[
        "capo_ec2.types.metadata_default_http_tokens_state.MetadataDefaultHttpTokensState"
    ] = None,
    http_put_response_hop_limit: Optional[
        "capo_ec2.types.boxed_integer.BoxedInteger"
    ] = None,
    http_endpoint: Optional[
        "capo_ec2.types.default_instance_metadata_endpoint_state.DefaultInstanceMetadataEndpointState"
    ] = None,
    instance_metadata_tags: Optional[
        "capo_ec2.types.default_instance_metadata_tags_state.DefaultInstanceMetadataTagsState"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    http_tokens_enforced: Optional[
        "capo_ec2.types.default_http_tokens_enforced_state.DefaultHttpTokensEnforcedState"
    ] = None,
) -> "capo_ec2.types.modify_instance_metadata_defaults_result.ModifyInstanceMetadataDefaultsResult":
    """<p>Modifies the default instance metadata service (IMDS) settings at the account level in the specified Amazon Web Services Region.</p> <note> <p>To remove a parameter's account-level default setting, specify <code>no-preference</code>. If an account-level setting is cleared with <code>no-preference</code>, then the instance launch considers the other instance metadata settings. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html#instance-metadata-options-order-of-precedence">Order of precedence for instance metadata options</a> in the <i>Amazon EC2 User Guide</i>.</p> </note>

    Args:
        http_tokens: <p>Indicates whether IMDSv2 is required.</p> <ul> <li> <p> <code>optional</code> – IMDSv2 is optional, which means that you can use either IMDSv2 or IMDSv1.</p> </li> <li> <p> <code>required</code> – IMDSv2 is required, which means that IMDSv1 is disabled, and you must use IMDSv2.</p> </li> </ul>
        http_put_response_hop_limit: <p>The maximum number of hops that the metadata token can travel. To indicate no preference, specify <code>-1</code>.</p> <p>Possible values: Integers from <code>1</code> to <code>64</code>, and <code>-1</code> to indicate no preference</p>
        http_endpoint: <p>Enables or disables the IMDS endpoint on an instance. When disabled, the instance metadata can't be accessed.</p>
        instance_metadata_tags: <p>Enables or disables access to an instance's tags from the instance metadata. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/work-with-tags-in-IMDS.html">View tags for your EC2 instances using instance metadata</a> in the <i>Amazon EC2 User Guide</i>.</p>
        dry_run: <p>Checks whether you have the required permissions for the operation, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        http_tokens_enforced: <p>Specifies whether to enforce the requirement of IMDSv2 on an instance at the time of launch. When enforcement is enabled, the instance can't launch unless IMDSv2 (<code>HttpTokens</code>) is set to <code>required</code>. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html#enforce-imdsv2-at-the-account-level">Enforce IMDSv2 at the account level</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.modify_instance_metadata_defaults_request.ModifyInstanceMetadataDefaultsRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.modify_instance_metadata_defaults_result.ModifyInstanceMetadataDefaultsResult"
    ]:
        import capo_ec2._operations.amazon_ec2.modify_instance_metadata_defaults

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.modify_instance_metadata_defaults.async_modify_instance_metadata_defaults(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ModifyInstanceMetadataDefaults")
    )
    input_: capo_ec2.types.modify_instance_metadata_defaults_request.ModifyInstanceMetadataDefaultsRequest = {}
    if http_tokens is not None:
        input_["http_tokens"] = http_tokens
    if http_put_response_hop_limit is not None:
        input_["http_put_response_hop_limit"] = http_put_response_hop_limit
    if http_endpoint is not None:
        input_["http_endpoint"] = http_endpoint
    if instance_metadata_tags is not None:
        input_["instance_metadata_tags"] = instance_metadata_tags
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if http_tokens_enforced is not None:
        input_["http_tokens_enforced"] = http_tokens_enforced

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output