Skip to content

import_model

import_model(
    source_model_arn: ComprehendModelArn,
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
    model_name: Optional[ComprehendArnName] = None,
    version_name: Optional[VersionName] = None,
    model_kms_key_id: Optional[KmsKeyId] = None,
    data_access_role_arn: Optional[IamRoleArn] = None,
    tags: Optional[TagList] = None,
) -> ImportModelResponse

Creates a new custom model that replicates a source custom model that you import. The source model can be in your Amazon Web Services account or another one.

If the source model is in another Amazon Web Services account, then it must have a resource-based policy that authorizes you to import it.

The source model must be in the same Amazon Web Services Region that you're using when you import. You can't import a model that's in a different Region.

Parameters:

  • source_model_arn (ComprehendModelArn) –

    The Amazon Resource Name (ARN) of the custom model to import.

  • model_name (Optional[ComprehendArnName], default: None ) –

    The name to assign to the custom model that is created in Amazon Comprehend by this import.

  • version_name (Optional[VersionName], default: None ) –

    The version name given to the custom model that is created by this import. Version names can have a maximum of 256 characters. Alphanumeric characters, hyphens (-) and underscores (_) are allowed. The version name must be unique among all models with the same classifier name in the account/Region.

  • model_kms_key_id (Optional[KmsKeyId], default: None ) –

    ID for the KMS key that Amazon Comprehend uses to encrypt trained custom models. The ModelKmsKeyId can be either of the following formats:

    • KMS Key ID: "1234abcd-12ab-34cd-56ef-1234567890ab"

    • Amazon Resource Name (ARN) of a KMS Key: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"

  • data_access_role_arn (Optional[IamRoleArn], default: None ) –

    The Amazon Resource Name (ARN) of the IAM role that grants Amazon Comprehend permission to use Amazon Key Management Service (KMS) to encrypt or decrypt the custom model.

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

    Tags to associate with the custom model that is created by this import. A tag is a key-value pair that adds as a metadata to a resource used by Amazon Comprehend. For example, a tag with "Sales" as the key might be added to a resource to indicate its use by the sales department.

Raises:

Source code in docs_src/capo_comprehend/_services/comprehend.py
def import_model(
    self,
    source_model_arn: "capo_comprehend.types.comprehend_model_arn.ComprehendModelArn",
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
    model_name: Optional[
        "capo_comprehend.types.comprehend_arn_name.ComprehendArnName"
    ] = None,
    version_name: Optional["capo_comprehend.types.version_name.VersionName"] = None,
    model_kms_key_id: Optional["capo_comprehend.types.kms_key_id.KmsKeyId"] = None,
    data_access_role_arn: Optional[
        "capo_comprehend.types.iam_role_arn.IamRoleArn"
    ] = None,
    tags: Optional["capo_comprehend.types.tag_list.TagList"] = None,
) -> "capo_comprehend.types.import_model_response.ImportModelResponse":
    """<p>Creates a new custom model that replicates a source custom model that you import. The source model can be in your Amazon Web Services account or another one.</p> <p>If the source model is in another Amazon Web Services account, then it must have a resource-based policy that authorizes you to import it.</p> <p>The source model must be in the same Amazon Web Services Region that you're using when you import. You can't import a model that's in a different Region.</p>

    Args:
        source_model_arn: <p>The Amazon Resource Name (ARN) of the custom model to import.</p>
        model_name: <p>The name to assign to the custom model that is created in Amazon Comprehend by this import.</p>
        version_name: <p>The version name given to the custom model that is created by this import. Version names can have a maximum of 256 characters. Alphanumeric characters, hyphens (-) and underscores (_) are allowed. The version name must be unique among all models with the same classifier name in the account/Region.</p>
        model_kms_key_id: <p>ID for the KMS key that Amazon Comprehend uses to encrypt trained custom models. The ModelKmsKeyId can be either of the following formats:</p> <ul> <li> <p>KMS Key ID: <code>"1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> <li> <p>Amazon Resource Name (ARN) of a KMS Key: <code>"arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> </ul>
        data_access_role_arn: <p>The Amazon Resource Name (ARN) of the IAM role that grants Amazon Comprehend permission to use Amazon Key Management Service (KMS) to encrypt or decrypt the custom model.</p>
        tags: <p>Tags to associate with the custom model that is created by this import. A tag is a key-value pair that adds as a metadata to a resource used by Amazon Comprehend. For example, a tag with "Sales" as the key might be added to a resource to indicate its use by the sales department.</p>

    Raises:
        capo_comprehend.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_comprehend.errors.invalid_request_exception.InvalidRequestException: <p>The request is invalid.</p>
        capo_comprehend.errors.kms_key_validation_exception.KmsKeyValidationException: <p>The KMS customer managed key (CMK) entered cannot be validated. Verify the key and re-enter it.</p>
        capo_comprehend.errors.resource_in_use_exception.ResourceInUseException: <p>The specified resource name is already in use. Use a different name and try your request again.</p>
        capo_comprehend.errors.resource_limit_exceeded_exception.ResourceLimitExceededException: <p>The maximum number of resources per account has been exceeded. Review the resources, and then try your request again.</p>
        capo_comprehend.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource ARN was not found. Check the ARN and try your request again.</p>
        capo_comprehend.errors.resource_unavailable_exception.ResourceUnavailableException: <p>The specified resource is not available. Check the resource and try your request again.</p>
        capo_comprehend.errors.too_many_requests_exception.TooManyRequestsException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_comprehend.errors.too_many_tags_exception.TooManyTagsException: <p>The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request. </p>
        capo_comprehend.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_comprehend.types.import_model_request.ImportModelRequest]",
    ) -> OperationResponse[
        "capo_comprehend.types.import_model_response.ImportModelResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.import_model

        output, http_response = (
            capo_comprehend._operations.comprehend_20171127.import_model.import_model(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ImportModel")
    )
    input_: capo_comprehend.types.import_model_request.ImportModelRequest = {
        "source_model_arn": source_model_arn
    }
    if model_name is not None:
        input_["model_name"] = model_name
    if version_name is not None:
        input_["version_name"] = version_name
    if model_kms_key_id is not None:
        input_["model_kms_key_id"] = model_kms_key_id
    if data_access_role_arn is not None:
        input_["data_access_role_arn"] = data_access_role_arn
    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