sagemaker.serve.bedrock_model_builder#
Holds the BedrockModelBuilder class.
Classes
|
Builder class for deploying models to Amazon Bedrock. |
- class sagemaker.serve.bedrock_model_builder.BedrockModelBuilder(model: ModelTrainer | TrainingJob | ModelPackage | None)[source]#
Bases:
objectBuilder class for deploying models to Amazon Bedrock.
This class provides functionality to deploy SageMaker models to Bedrock using either model import jobs or custom model creation, depending on the model type (Nova models vs. other models).
- Parameters:
model – The model to deploy. Can be a ModelTrainer, TrainingJob, or ModelPackage instance.
- create_deployment(model_arn: str, deployment_name: str | None = None, poll_interval: int = 60, max_wait: int = 3600, **kwargs) Dict[str, Any][source]#
Create a deployment for a Nova custom model.
Polls the model status until it becomes Active before creating the deployment, then polls the deployment status until it becomes Active.
- Parameters:
model_arn – ARN of the custom model to deploy.
deployment_name – Name for the deployment.
poll_interval – Seconds between status checks. Defaults to 60 for model, 30 for deployment.
max_wait – Maximum seconds to wait per polling phase. Defaults to 3600.
**kwargs – Additional parameters for create_custom_model_deployment.
- Returns:
Response from Bedrock create_custom_model_deployment API.
- Raises:
RuntimeError – If the model or deployment fails or times out.
ValueError – If model_arn is not provided.
- deploy(job_name: str | None = None, imported_model_name: str | None = None, custom_model_name: str | None = None, role_arn: str | None = None, job_tags: list | None = None, imported_model_tags: list | None = None, model_tags: list | None = None, client_request_token: str | None = None, imported_model_kms_key_id: str | None = None, deployment_name: str | None = None) Dict[str, Any][source]#
Deploy the model to Bedrock.
Automatically detects if the model is a Nova model and uses the appropriate Bedrock API (create_custom_model for Nova, create_model_import_job for others). For Nova models, also creates a custom model deployment for inference.
- Parameters:
job_name – Name for the model import job (non-Nova models only).
imported_model_name – Name for the imported model (non-Nova models only).
custom_model_name – Name for the custom model (Nova models only).
role_arn – IAM role ARN with permissions for Bedrock operations.
job_tags – Tags for the import job (non-Nova models only).
imported_model_tags – Tags for the imported model (non-Nova models only).
model_tags – Tags for the custom model (Nova models only).
client_request_token – Unique token for idempotency (non-Nova models only).
imported_model_kms_key_id – KMS key ID for encryption (non-Nova models only).
deployment_name – Name for the deployment (Nova models only). If not provided, defaults to custom_model_name suffixed with ‘-deployment’.
- Returns:
Response from Bedrock API. For Nova models, returns the create_custom_model_deployment response. For others, returns the create_model_import_job response.
- Raises:
ValueError – If model_package is not set or required parameters are missing.