Skip to content

create_service_linked_role

create_service_linked_role(
    aws_service_name: groupNameType,
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    description: Optional[roleDescriptionType] = None,
    custom_suffix: Optional[customSuffixType] = None,
) -> CreateServiceLinkedRoleResponse

Creates an IAM role that is linked to a specific Amazon Web Services service. The service controls the attached policies and when the role can be deleted. This helps ensure that the service is not broken by an unexpectedly changed or deleted role, which could put your Amazon Web Services resources into an unknown state. Allowing the service to control the role helps improve service stability and proper cleanup when a service and its role are no longer needed. For more information, see Using service-linked roles in the IAM User Guide.

To attach a policy to this service-linked role, you must make the request using the Amazon Web Services service that depends on this role.

Parameters:

  • aws_service_name (groupNameType) –

    The service principal for the Amazon Web Services service to which this role is attached. You use a string similar to a URL but without the http:// in front. For example: elasticbeanstalk.amazonaws.com.

    Service principals are unique and case-sensitive. To find the exact service principal for your service-linked role, see Amazon Web Services services that work with IAM in the IAM User Guide. Look for the services that have Yes in the Service-Linked Role column. Choose the Yes link to view the service-linked role documentation for that service.

  • description (Optional[roleDescriptionType], default: None ) –

    The description of the role.

  • custom_suffix (Optional[customSuffixType], default: None ) –

    A string that you provide, which is combined with the service-provided prefix to form the complete role name. If you make multiple requests for the same service, then you must supply a different CustomSuffix for each request. Otherwise the request fails with a duplicate role name error. For example, you could add -1 or -debug to the suffix.

    Some services do not support the CustomSuffix parameter. If you provide an optional suffix and the operation fails, try the operation again without the suffix.

Raises:

  • 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.

  • NoSuchEntityException –

    The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.

  • 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.

Source code in docs_src/capo_iam/_services/iam.py
def create_service_linked_role(
    self,
    aws_service_name: "capo_iam.types.group_name_type.groupNameType",
    *,
    config_overrides: Optional[IAMClientConfig] = None,
    description: Optional[
        "capo_iam.types.role_description_type.roleDescriptionType"
    ] = None,
    custom_suffix: Optional[
        "capo_iam.types.custom_suffix_type.customSuffixType"
    ] = None,
) -> "capo_iam.types.create_service_linked_role_response.CreateServiceLinkedRoleResponse":
    """<p>Creates an IAM role that is linked to a specific Amazon Web Services service. The service controls the attached policies and when the role can be deleted. This helps ensure that the service is not broken by an unexpectedly changed or deleted role, which could put your Amazon Web Services resources into an unknown state. Allowing the service to control the role helps improve service stability and proper cleanup when a service and its role are no longer needed. For more information, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html">Using service-linked roles</a> in the <i>IAM User Guide</i>. </p> <p>To attach a policy to this service-linked role, you must make the request using the Amazon Web Services service that depends on this role.</p>

    Args:
        aws_service_name: <p>The service principal for the Amazon Web Services service to which this role is attached. You use a string similar to a URL but without the http:// in front. For example: <code>elasticbeanstalk.amazonaws.com</code>. </p> <p>Service principals are unique and case-sensitive. To find the exact service principal for your service-linked role, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html">Amazon Web Services services that work with IAM</a> in the <i>IAM User Guide</i>. Look for the services that have <b>Yes </b>in the <b>Service-Linked Role</b> column. Choose the <b>Yes</b> link to view the service-linked role documentation for that service.</p>
        description: <p>The description of the role.</p>
        custom_suffix: <p></p> <p>A string that you provide, which is combined with the service-provided prefix to form the complete role name. If you make multiple requests for the same service, then you must supply a different <code>CustomSuffix</code> for each request. Otherwise the request fails with a duplicate role name error. For example, you could add <code>-1</code> or <code>-debug</code> to the suffix.</p> <p>Some services do not support the <code>CustomSuffix</code> parameter. If you provide an optional suffix and the operation fails, try the operation again without the suffix.</p>

    Raises:
        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.no_such_entity_exception.NoSuchEntityException: <p>The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.</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.
    """

    def _handler(
        req: "OperationRequest[capo_iam.types.create_service_linked_role_request.CreateServiceLinkedRoleRequest]",
    ) -> OperationResponse[
        "capo_iam.types.create_service_linked_role_response.CreateServiceLinkedRoleResponse"
    ]:
        import capo_iam._operations.aws_identity_management_v20100508.create_service_linked_role

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateServiceLinkedRole")
    )
    input_: capo_iam.types.create_service_linked_role_request.CreateServiceLinkedRoleRequest = {
        "aws_service_name": aws_service_name
    }
    if description is not None:
        input_["description"] = description
    if custom_suffix is not None:
        input_["custom_suffix"] = custom_suffix

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