import boto3
# Create SageMaker client
sagemaker = boto3.client(
"sagemaker",
region_name="us-east-1"
)
# Define deployment names
model_name = "llm-api-model"
endpoint_config_name = "llm-api-config"
endpoint_name = "llm-api-endpoint"
# Define ECR Docker image
image_uri = (
"123456789012.dkr.ecr.us-east-1.amazonaws.com/"
"llm-api:latest"
)
# Define SageMaker IAM role
role_arn = (
"arn:aws:iam::123456789012:"
"role/SageMakerRole"
)
# Create SageMaker model
sagemaker.create_model(
ModelName=model_name,
PrimaryContainer={
"Image": image_uri
},
ExecutionRoleArn=role_arn
)
# Create endpoint configuration
sagemaker.create_endpoint_config(
EndpointConfigName=endpoint_config_name,
ProductionVariants=[
{
"VariantName": "AllTraffic",
"ModelName": model_name,
"InstanceType": "ml.m5.large",
"InitialInstanceCount": 1,
"InitialVariantWeight": 1.0
}
]
)
# Create SageMaker endpoint
sagemaker.create_endpoint(
EndpointName=endpoint_name,
EndpointConfigName=endpoint_config_name
)
# Print deployment information
print("SageMaker endpoint creation started")
print("Endpoint:", endpoint_name)