When working with AI/ML workloads, you might have custom-trained models on your local machine or in cloud storage that you want to deploy into an AWS VM (such as an EC2 instance). One efficient way to do this is by using AWS CLI's sync
command.
In this guide, we’ll walk through syncing custom models into an AWS VM so you can start using them quickly.
📦 Prerequisites
Before you begin, ensure that you have:
- An AWS account with access keys configured.
- An S3 bucket to store your models.
- AWS CLI installed on your local machine.
pip install awscli
- An EC2 VM with the necessary permissions (IAM role allowing S3 access).
🛠 Step 1: Upload Your Model to S3
First, upload your model from your local machine to an S3 bucket.
aws s3 cp ./my_model/ s3://my-ml-models-bucket/my_model/ --recursive
✅ This command copies all files from the my_model
folder into your bucket.
🔄 Step 2: Sync Model from S3 to Your AWS VM
SSH into your EC2 VM:
ssh -i my-key.pem ec2-user@<EC2_PUBLIC_IP>
Now, run the sync command:
aws s3 sync s3://my-ml-models-bucket/my_model/ /home/ec2-user/models/my_model/
✅ This will only copy missing or updated files, making deployments faster.
⚡ Step 3: Verify the Model Files
Once synced, check the model directory:
ls -lh /home/ec2-user/models/my_model/
You should see your model files ready to be used.
💡 Pro Tips
- Versioning: Use S3 bucket versioning to roll back to older models if needed.
aws s3api put-bucket-versioning --bucket my-ml-models-bucket --versioning-configuration Status=Enabled
- Automation: Add the sync command to a cron job or CI/CD pipeline for automated model updates.
-
Security: Ensure your EC2 IAM role has minimal permissions — e.g.,
s3:GetObject
for the specific bucket.
🚀 Next Steps
With your models on the AWS VM, you can:
- Integrate them into APIs.
- Use them in batch processing jobs.
- Serve them via inference servers like FastAPI, TorchServe, or TensorFlow Serving.
Final Thought:
AWS CLI sync
is a simple yet powerful way to keep your AWS VMs up to date with your latest custom AI models without manual file transfers.
Top comments (0)