| name | sagemaker |
| description | Manage Amazon SageMaker notebooks, training jobs, models, endpoints, and pipelines via AWS CLI. |
| metadata | {"openclaw":{"emoji":"🧠","requires":{"bins":["aws"]}}} |
Amazon SageMaker
Use this skill for machine learning operations: managing notebook instances, training jobs, model hosting, batch transforms, endpoints, and ML pipelines.
Prerequisites
- AWS CLI v2 configured with valid credentials
- IAM permissions:
sagemaker:* for full access, or scoped policies
- SageMaker execution role with access to S3, ECR, and other needed services
Common Operations
List and Inspect (Read-Only)
aws sagemaker list-notebook-instances \
--query 'NotebookInstances[*].[NotebookInstanceName,InstanceType,NotebookInstanceStatus]' --output table
aws sagemaker describe-notebook-instance --notebook-instance-name <name>
aws sagemaker list-training-jobs --sort-by CreationTime --sort-order Descending \
--query 'TrainingJobSummaries[*].[TrainingJobName,TrainingJobStatus,CreationTime]' --output table
aws sagemaker describe-training-job --training-job-name <job-name>
aws sagemaker list-models \
--query 'Models[*].[ModelName,CreationTime]' --output table
aws sagemaker list-endpoints \
--query 'Endpoints[*].[EndpointName,EndpointStatus,CreationTime]' --output table
aws sagemaker describe-endpoint --endpoint-name <endpoint-name>
aws sagemaker list-endpoint-configs \
--query 'EndpointConfigs[*].[EndpointConfigName,CreationTime]' --output table
aws sagemaker list-processing-jobs --sort-by CreationTime --sort-order Descending \
--query 'ProcessingJobSummaries[*].[ProcessingJobName,ProcessingJobStatus]' --output table
aws sagemaker list-pipelines \
--query 'PipelineSummaries[*].[PipelineName,PipelineStatus]' --output table
aws sagemaker list-pipeline-executions --pipeline-name <pipeline-name> \
--query 'PipelineExecutionSummaries[*].[PipelineExecutionArn,PipelineExecutionStatus,StartTime]' --output table
aws sagemaker list-experiments \
--query 'ExperimentSummaries[*].[ExperimentName,CreationTime]' --output table
aws sagemaker list-model-packages --output table
aws sagemaker list-transform-jobs --sort-by CreationTime --sort-order Descending \
--query 'TransformJobSummaries[*].[TransformJobName,TransformJobStatus]' --output table
Notebook Instances
⚠️ Cost note: Notebook instances charge per hour while running. ml.t3.medium: ~$0.05/hr. ml.p3.2xlarge (GPU): ~$3.83/hr. Stop when not in use!
aws sagemaker create-notebook-instance \
--notebook-instance-name <name> \
--instance-type ml.t3.medium \
--role-arn <sagemaker-role-arn> \
--volume-size-in-gb 20
aws sagemaker start-notebook-instance --notebook-instance-name <name>
aws sagemaker stop-notebook-instance --notebook-instance-name <name>
aws sagemaker create-presigned-notebook-instance-url \
--notebook-instance-name <name> \
--query 'AuthorizedUrl' --output text
Training Jobs
aws sagemaker create-training-job \
--training-job-name <job-name> \
--algorithm-specification '{
"TrainingImage": "<ecr-image-uri>",
"TrainingInputMode": "File"
}' \
--role-arn <sagemaker-role-arn> \
--input-data-config '[{
"ChannelName": "train",
"DataSource": {"S3DataSource": {"S3DataType": "S3Prefix", "S3Uri": "s3://<bucket>/train/"}}
}]' \
--output-data-config '{"S3OutputPath": "s3://<bucket>/output/"}' \
--resource-config '{
"InstanceType": "ml.m5.xlarge",
"InstanceCount": 1,
"VolumeSizeInGB": 50
}' \
--stopping-condition '{"MaxRuntimeInSeconds": 3600}' \
--hyper-parameters '{"epochs": "10", "batch_size": "32"}'
aws sagemaker stop-training-job --training-job-name <job-name>
aws logs get-log-events \
--log-group-name /aws/sagemaker/TrainingJobs \
--log-stream-name <job-name>/algo-1 \
--query 'events[*].message' --output text
Models and Endpoints
aws sagemaker create-model \
--model-name <model-name> \
--primary-container '{
"Image": "<ecr-image-uri>",
"ModelDataUrl": "s3://<bucket>/output/<job-name>/output/model.tar.gz"
}' \
--execution-role-arn <sagemaker-role-arn>
aws sagemaker create-endpoint-config \
--endpoint-config-name <config-name> \
--production-variants '[{
"VariantName": "primary",
"ModelName": "<model-name>",
"InstanceType": "ml.m5.large",
"InitialInstanceCount": 1,
"InitialVariantWeight": 1.0
}]'
aws sagemaker create-endpoint \
--endpoint-name <endpoint-name> \
--endpoint-config-name <config-name>
aws sagemaker-runtime invoke-endpoint \
--endpoint-name <endpoint-name> \
--content-type application/json \
--body '{"instances": [{"features": [1.0, 2.0, 3.0]}]}' \
/dev/stdout
aws sagemaker update-endpoint \
--endpoint-name <endpoint-name> \
--endpoint-config-name <new-config-name>
Batch Transform
aws sagemaker create-transform-job \
--transform-job-name <job-name> \
--model-name <model-name> \
--transform-input '{
"DataSource": {"S3DataSource": {"S3DataType": "S3Prefix", "S3Uri": "s3://<bucket>/input/"}},
"ContentType": "text/csv"
}' \
--transform-output '{"S3OutputPath": "s3://<bucket>/predictions/"}' \
--transform-resources '{"InstanceType": "ml.m5.xlarge", "InstanceCount": 1}'
Delete / Destructive
🛑 DESTRUCTIVE — Always confirm with the user before executing any of these commands.
aws sagemaker delete-endpoint --endpoint-name <endpoint-name>
aws sagemaker delete-endpoint-config --endpoint-config-name <config-name>
aws sagemaker delete-model --model-name <model-name>
aws sagemaker delete-notebook-instance --notebook-instance-name <name>
Safety Rules
- NEVER delete endpoints or models without explicit user confirmation.
- NEVER expose or log AWS credentials or model data.
- ALWAYS stop notebook instances when not in use — they charge per hour.
- ALWAYS set
MaxRuntimeInSeconds on training jobs to prevent runaway costs.
- WARN about GPU instance costs before creating training jobs or endpoints.
- WARN that endpoints charge continuously until deleted.
Best Practices
- Always set stopping conditions on training jobs.
- Use spot instances for training to save 60-90%.
- Stop notebook instances when not in use.
- Use SageMaker Pipelines for reproducible ML workflows.
- Monitor endpoint invocation metrics to right-size instances.
Common Patterns
Pattern: End-to-End ML Workflow
aws sagemaker create-training-job --training-job-name my-model-v1 ...
aws sagemaker wait training-job-completed-or-stopped --training-job-name my-model-v1
MODEL_DATA=$(aws sagemaker describe-training-job --training-job-name my-model-v1 \
--query 'ModelArtifacts.S3ModelArtifacts' --output text)
aws sagemaker create-model --model-name my-model-v1 \
--primary-container "{\"Image\":\"<image>\",\"ModelDataUrl\":\"$MODEL_DATA\"}" \
--execution-role-arn <role>
aws sagemaker create-endpoint-config --endpoint-config-name my-config-v1 ...
aws sagemaker create-endpoint --endpoint-name my-endpoint --endpoint-config-name my-config-v1
Pattern: Check Running Costs
echo "=== Running Notebooks ==="
aws sagemaker list-notebook-instances --status-equals InService \
--query 'NotebookInstances[*].[NotebookInstanceName,InstanceType]' --output table
echo "=== Active Endpoints ==="
aws sagemaker list-endpoints --status-equals InService \
--query 'Endpoints[*].[EndpointName]' --output table
Troubleshooting
| Error | Cause | Fix |
|---|
ResourceNotFound | Resource doesn't exist | Verify name with list commands |
| Training job failed | Algorithm error or resource issue | Check CloudWatch logs for the training job |
| Endpoint creation stuck | Instance provisioning issue | Check describe-endpoint for failure reason |
ModelError on invoke | Model loading or inference error | Check endpoint CloudWatch logs |
ThrottlingException | API rate limit | Reduce request rate; use exponential backoff |
| High endpoint latency | Instance undersized | Scale up instance type or add auto-scaling |