Skip to content

associate_iam_instance_profile async

associate_iam_instance_profile(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    iam_instance_profile: Optional[IamInstanceProfileSpecification] = None,
    instance_id: Optional[InstanceId] = None,
) -> AssociateIamInstanceProfileResult

Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.

Parameters:

Raises:

Examples:

To associate an IAM instance profile with an instance This example associates an IAM instance profile named admin-role with the specified instance.

>>> await client.associate_iam_instance_profile(iam_instance_profile={'Name': 'admin-role'}, instance_id='i-123456789abcde123')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def associate_iam_instance_profile(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    iam_instance_profile: Optional[
        "capo_ec2.types.iam_instance_profile_specification.IamInstanceProfileSpecification"
    ] = None,
    instance_id: Optional["capo_ec2.types.instance_id.InstanceId"] = None,
) -> "capo_ec2.types.associate_iam_instance_profile_result.AssociateIamInstanceProfileResult":
    """<p>Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.</p>

    Args:
        iam_instance_profile: <p>The IAM instance profile.</p>
        instance_id: <p>The ID of the instance.</p>

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

    Examples:
        To associate an IAM instance profile with an instance
        This example associates an IAM instance profile named admin-role with the specified instance.

        >>> await client.associate_iam_instance_profile(iam_instance_profile={'Name': 'admin-role'}, instance_id='i-123456789abcde123')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.associate_iam_instance_profile_request.AssociateIamInstanceProfileRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.associate_iam_instance_profile_result.AssociateIamInstanceProfileResult"
    ]:
        import capo_ec2._operations.amazon_ec2.associate_iam_instance_profile

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssociateIamInstanceProfile")
    )
    input_: capo_ec2.types.associate_iam_instance_profile_request.AssociateIamInstanceProfileRequest = {}
    if iam_instance_profile is not None:
        input_["iam_instance_profile"] = iam_instance_profile
    if instance_id is not None:
        input_["instance_id"] = instance_id

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