Creates a new custom model in Amazon Bedrock. After the model is active, you can use it for inference.
You can provide the model data source in one of the following ways:
-
customModelDataSource — Specify a SageMaker AI model package ARN. Amazon Bedrock resolves the model package to retrieve the model artifacts. This is the preferred method for new SageMaker AI training outputs.
-
modelSourceConfig — Specify an Amazon S3 URI pointing to the Amazon-managed Amazon S3 bucket containing your model artifacts.
To use the model for inference, you must purchase Provisioned Throughput for it. You can't use On-demand inference with these custom models. For more information about Provisioned Throughput, see Provisioned Throughput.
The model appears in ListCustomModels with a customizationType of imported. To track the status of the new model, you use the GetCustomModel API operation. The model can be in the following states:
-
Creating - Initial state during validation and registration
-
Active - Model is ready for use in inference
-
Failed - Creation process encountered an error
Related APIs
Parameters:
-
model_name
(CustomModelName)
–
A unique name for the custom model.
-
model_source_config
(Optional[ModelDataSource], default:
None
)
–
The data source for the model. The Amazon S3 URI in the model source must be for the Amazon-managed Amazon S3 bucket containing your model artifacts.
-
custom_model_data_source
(Optional[CustomModelDataSource], default:
None
)
–
The data source for the custom model. Use this field to specify a SageMaker AI model package ARN as the source for your custom model. Amazon Bedrock resolves the model package to retrieve the model artifacts.
You can specify either customModelDataSource or modelSourceConfig, but not both.
-
model_kms_key_arn
(Optional[KmsKeyArn], default:
None
)
–
The Amazon Resource Name (ARN) of the customer managed KMS key to encrypt the custom model. If you don't provide a KMS key, Amazon Bedrock uses an Amazon Web Services-managed KMS key to encrypt the model.
If you provide a customer managed KMS key, your Amazon Bedrock service role must have permissions to use it. For more information see Encryption of imported models.
-
role_arn
(Optional[RoleArn], default:
None
)
–
The Amazon Resource Name (ARN) of an IAM service role that Amazon Bedrock assumes to perform tasks on your behalf. This role must have permissions to access the Amazon S3 bucket containing your model artifacts and the KMS key (if specified). For more information, see Setting up an IAM service role for importing models in the Amazon Bedrock User Guide.
This field is required when you use modelSourceConfig with an Amazon S3 data source. It is not required when you use customModelDataSource with a model package ARN, because Amazon Bedrock uses its own credentials to access the model artifacts.
-
model_tags
(Optional[TagList], default:
None
)
–
A list of key-value pairs to associate with the custom model resource. You can use these tags to organize and identify your resources.
For more information, see Tagging resources in the Amazon Bedrock User Guide.
-
client_request_token
(Optional[IdempotencyToken], default:
None
)
–
A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency.
Raises:
-
AccessDeniedException
–
The request is denied because of missing access permissions.
-
ConflictException
–
Error occurred because of a conflict while performing an operation.
-
InternalServerException
–
An internal server error occurred. Retry your request.
-
ResourceNotFoundException
–
The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.
-
ServiceQuotaExceededException
–
The number of requests exceeds the service quota. Resubmit your request later.
-
ThrottlingException
–
The number of requests exceeds the limit. Resubmit your request later.
-
TooManyTagsException
–
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.
-
ValidationException
–
Input validation failed. Check your request parameters and retry the request.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
Successful CreateCustomModel API call
>>> await client.create_custom_model(model_name='SampleModel', model_source_config={'s3DataSource': {'s3Uri': 's3://my-bucket/folder'}}, role_arn='arn:aws:iam::123456789012:role/SampleRole', model_kms_key_arn='arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab', model_tags=[{'key': 'foo', 'value': 'foo'}, {'key': 'foo', 'value': 'foo'}], client_request_token='foo')
Source code in docs_src/capo_bedrock/_services/async_bedrock.py
| async def create_custom_model(
self,
model_name: "capo_bedrock.types.custom_model_name.CustomModelName",
*,
config_overrides: Optional[AsyncBedrockClientConfig] = None,
model_source_config: Optional[
"capo_bedrock.types.model_data_source.ModelDataSource"
] = None,
custom_model_data_source: Optional[
"capo_bedrock.types.custom_model_data_source.CustomModelDataSource"
] = None,
model_kms_key_arn: Optional["capo_bedrock.types.kms_key_arn.KmsKeyArn"] = None,
role_arn: Optional["capo_bedrock.types.role_arn.RoleArn"] = None,
model_tags: Optional["capo_bedrock.types.tag_list.TagList"] = None,
client_request_token: Optional[
"capo_bedrock.types.idempotency_token.IdempotencyToken"
] = None,
) -> "capo_bedrock.types.create_custom_model_response.CreateCustomModelResponse":
"""<p>Creates a new custom model in Amazon Bedrock. After the model is active, you can use it for inference.</p> <p>You can provide the model data source in one of the following ways:</p> <ul> <li> <p> <code>customModelDataSource</code> — Specify a SageMaker AI model package ARN. Amazon Bedrock resolves the model package to retrieve the model artifacts. This is the preferred method for new SageMaker AI training outputs.</p> </li> <li> <p> <code>modelSourceConfig</code> — Specify an Amazon S3 URI pointing to the Amazon-managed Amazon S3 bucket containing your model artifacts.</p> </li> </ul> <p>To use the model for inference, you must purchase Provisioned Throughput for it. You can't use On-demand inference with these custom models. For more information about Provisioned Throughput, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-throughput.html">Provisioned Throughput</a>.</p> <p>The model appears in <code>ListCustomModels</code> with a <code>customizationType</code> of <code>imported</code>. To track the status of the new model, you use the <code>GetCustomModel</code> API operation. The model can be in the following states:</p> <ul> <li> <p> <code>Creating</code> - Initial state during validation and registration</p> </li> <li> <p> <code>Active</code> - Model is ready for use in inference</p> </li> <li> <p> <code>Failed</code> - Creation process encountered an error</p> </li> </ul> <p> <b>Related APIs</b> </p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GetCustomModel.html">GetCustomModel</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_ListCustomModels.html">ListCustomModels</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_DeleteCustomModel.html">DeleteCustomModel</a> </p> </li> </ul>
Args:
model_name: <p>A unique name for the custom model.</p>
model_source_config: <p>The data source for the model. The Amazon S3 URI in the model source must be for the Amazon-managed Amazon S3 bucket containing your model artifacts.</p>
custom_model_data_source: <p>The data source for the custom model. Use this field to specify a SageMaker AI model package ARN as the source for your custom model. Amazon Bedrock resolves the model package to retrieve the model artifacts.</p> <p>You can specify either <code>customModelDataSource</code> or <code>modelSourceConfig</code>, but not both.</p>
model_kms_key_arn: <p>The Amazon Resource Name (ARN) of the customer managed KMS key to encrypt the custom model. If you don't provide a KMS key, Amazon Bedrock uses an Amazon Web Services-managed KMS key to encrypt the model. </p> <p>If you provide a customer managed KMS key, your Amazon Bedrock service role must have permissions to use it. For more information see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/encryption-import-model.html">Encryption of imported models</a>. </p>
role_arn: <p>The Amazon Resource Name (ARN) of an IAM service role that Amazon Bedrock assumes to perform tasks on your behalf. This role must have permissions to access the Amazon S3 bucket containing your model artifacts and the KMS key (if specified). For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-import-iam-role.html">Setting up an IAM service role for importing models</a> in the Amazon Bedrock User Guide.</p> <p>This field is required when you use <code>modelSourceConfig</code> with an Amazon S3 data source. It is not required when you use <code>customModelDataSource</code> with a model package ARN, because Amazon Bedrock uses its own credentials to access the model artifacts.</p>
model_tags: <p>A list of key-value pairs to associate with the custom model resource. You can use these tags to organize and identify your resources.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/tagging.html">Tagging resources</a> in the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html">Amazon Bedrock User Guide</a>.</p>
client_request_token: <p>A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p>
Raises:
capo_bedrock.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
capo_bedrock.errors.conflict_exception.ConflictException: <p>Error occurred because of a conflict while performing an operation.</p>
capo_bedrock.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
capo_bedrock.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.</p>
capo_bedrock.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
capo_bedrock.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
capo_bedrock.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_bedrock.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
capo_bedrock.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
Successful CreateCustomModel API call
>>> await client.create_custom_model(model_name='SampleModel', model_source_config={'s3DataSource': {'s3Uri': 's3://my-bucket/folder'}}, role_arn='arn:aws:iam::123456789012:role/SampleRole', model_kms_key_arn='arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab', model_tags=[{'key': 'foo', 'value': 'foo'}, {'key': 'foo', 'value': 'foo'}], client_request_token='foo')
"""
async def _handler(
req: "AsyncOperationRequest[capo_bedrock.types.create_custom_model_request.CreateCustomModelRequest]",
) -> AsyncOperationResponse[
"capo_bedrock.types.create_custom_model_response.CreateCustomModelResponse"
]:
import capo_bedrock._operations.amazon_bedrock_control_plane_service.create_custom_model
(
output,
http_response,
) = await capo_bedrock._operations.amazon_bedrock_control_plane_service.create_custom_model.async_create_custom_model(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("CreateCustomModel")
)
input_: capo_bedrock.types.create_custom_model_request.CreateCustomModelRequest = {
"model_name": model_name
}
if model_source_config is not None:
input_["model_source_config"] = model_source_config
if custom_model_data_source is not None:
input_["custom_model_data_source"] = custom_model_data_source
if model_kms_key_arn is not None:
input_["model_kms_key_arn"] = model_kms_key_arn
if role_arn is not None:
input_["role_arn"] = role_arn
if model_tags is not None:
input_["model_tags"] = model_tags
if client_request_token is None:
client_request_token = str(uuid.uuid4())
input_["client_request_token"] = client_request_token
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|