Skip to content

create_instance_profile

create_instance_profile(
    instance_profile_name: instanceProfileNameType,
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    path: Optional[pathType] = None,
    tags: Optional[tagListType] = None,
) -> CreateInstanceProfileResponse

Creates a new instance profile. For information about instance profiles, see Using roles for applications on Amazon EC2 in the IAM User Guide, and Instance profiles in the Amazon EC2 User Guide.

For information about the number of instance profiles you can create, see IAM object quotas in the IAM User Guide.

Parameters:

  • instance_profile_name (instanceProfileNameType) –

    The name of the instance profile to create.

    This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

  • path (Optional[pathType], default: None ) –

    The path to the instance profile. For more information about paths, see IAM Identifiers in the IAM User Guide.

    This parameter is optional. If it is not included, it defaults to a slash (/).

    This parameter allows (through its regex pattern) a string of characters consisting of either a forward slash (/) by itself or a string that must begin and end with forward slashes. In addition, it can contain any ASCII character from the ! (\u0021) through the DEL character (\u007F), including most punctuation characters, digits, and upper and lowercased letters.

  • tags (Optional[tagListType], default: None ) –

    A list of tags that you want to attach to the newly created IAM instance profile. Each tag consists of a key name and an associated value. For more information about tagging, see Tagging IAM resources in the IAM User Guide.

    If any one of the tags is invalid or if you exceed the allowed maximum number of tags, then the entire request fails and the resource is not created.

Raises:

  • ConcurrentModificationException –

    The request was rejected because multiple requests to change this object were submitted simultaneously. Wait a few minutes and submit your request again.

  • EntityAlreadyExistsException –

    The request was rejected because it attempted to create a resource that already exists.

  • InvalidInputException –

    The request was rejected because an invalid or out-of-range value was supplied for an input parameter.

  • LimitExceededException –

    The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.

  • ServiceFailureException –

    The request processing has failed because of an unknown error, exception or failure.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To create an instance profile The following command creates an instance profile named Webserver that is ready to have a role attached and then be associated with an EC2 instance.

>>> client.create_instance_profile(instance_profile_name='Webserver')
Source code in docs_src/capo_iam/_services/iam.py
def create_instance_profile(
    self,
    instance_profile_name: "capo_iam.types.instance_profile_name_type.instanceProfileNameType",
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    path: Optional["capo_iam.types.path_type.pathType"] = None,
    tags: Optional["capo_iam.types.tag_list_type.tagListType"] = None,
) -> (
    "capo_iam.types.create_instance_profile_response.CreateInstanceProfileResponse"
):
    r"""<p> Creates a new instance profile. For information about instance profiles, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html">Using roles for applications on Amazon EC2</a> in the <i>IAM User Guide</i>, and <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#ec2-instance-profile">Instance profiles</a> in the <i>Amazon EC2 User Guide</i>.</p> <p> For information about the number of instance profiles you can create, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html">IAM object quotas</a> in the <i>IAM User Guide</i>.</p>

    Args:
        instance_profile_name: <p>The name of the instance profile to create.</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-</p>
        path: <p> The path to the instance profile. For more information about paths, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html">IAM Identifiers</a> in the <i>IAM User Guide</i>.</p> <p>This parameter is optional. If it is not included, it defaults to a slash (/).</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters consisting of either a forward slash (/) by itself or a string that must begin and end with forward slashes. In addition, it can contain any ASCII character from the ! (<code>\u0021</code>) through the DEL character (<code>\u007F</code>), including most punctuation characters, digits, and upper and lowercased letters.</p>
        tags: <p>A list of tags that you want to attach to the newly created IAM instance profile. Each tag consists of a key name and an associated value. For more information about tagging, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html">Tagging IAM resources</a> in the <i>IAM User Guide</i>.</p> <note> <p>If any one of the tags is invalid or if you exceed the allowed maximum number of tags, then the entire request fails and the resource is not created.</p> </note>

    Raises:
        capo_iam.errors.concurrent_modification_exception.ConcurrentModificationException: <p>The request was rejected because multiple requests to change this object were submitted simultaneously. Wait a few minutes and submit your request again.</p>
        capo_iam.errors.entity_already_exists_exception.EntityAlreadyExistsException: <p>The request was rejected because it attempted to create a resource that already exists.</p>
        capo_iam.errors.invalid_input_exception.InvalidInputException: <p>The request was rejected because an invalid or out-of-range value was supplied for an input parameter.</p>
        capo_iam.errors.limit_exceeded_exception.LimitExceededException: <p>The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.</p>
        capo_iam.errors.service_failure_exception.ServiceFailureException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
        capo_iam.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create an instance profile
        The following command creates an instance profile named Webserver that is ready to have a role attached and then be associated with an EC2 instance.

        >>> client.create_instance_profile(instance_profile_name='Webserver')
    """

    def _handler(
        req: "OperationRequest[capo_iam.types.create_instance_profile_request.CreateInstanceProfileRequest]",
    ) -> OperationResponse[
        "capo_iam.types.create_instance_profile_response.CreateInstanceProfileResponse"
    ]:
        import capo_iam._operations.aws_identity_management_v20100508.create_instance_profile

        output, http_response = (
            capo_iam._operations.aws_identity_management_v20100508.create_instance_profile.create_instance_profile(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateInstanceProfile")
    )
    input_: capo_iam.types.create_instance_profile_request.CreateInstanceProfileRequest = {
        "instance_profile_name": instance_profile_name
    }
    if path is not None:
        input_["path"] = path
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output