Your First Deployment 🚀
Now that your code is tested and working locally, it's time to package it up and get it ready for AWS! We'll create a Docker container and push it to Amazon's Elastic Container Registry (ECR).
What is Docker? 🐳
Think of Docker Like This
Imagine you're moving to a new house:
- Instead of moving furniture piece by piece, you put everything in a shipping container
- The container has everything needed - furniture, appliances, decorations
- The container works the same no matter what truck carries it
Docker does the same thing for your code:
- Instead of installing pieces separately, everything goes in a container
- The container has your code, Python, libraries - everything it needs
- The container runs the same way everywhere - your computer, AWS, anywhere!
Prerequisites ✅
Before starting, make sure you have:
- [x] Locally tested code (from previous section)
- [x] Docker Desktop installed and running
- [x] AWS CLI installed and configured
- [x] Git repository with your latest code
Quick Docker Check
Run this command to verify Docker is working:
If you see a version number, you're good to go!Step 1: Prepare Your Code 📝
-
Make sure your code is committed to Git:
-
Verify your project structure:
Step 2: Build Your Docker Image 🏗️
- Build your image locally:
What's Happening?
docker build
- Creates your container--no-cache
- Ensures fresh build-t arcade-payment-api
- Names your container.
- Uses current directory
-
Test your Docker image locally:
-
In another terminal, test the API:
You should see:
Step 3: Prepare for AWS ECR 🌥️
-
Login to AWS ECR (replace
region
with your AWS region): -
Create an ECR repository:
-
Note your repository URI:
Finding Your Account ID
You can find your AWS account ID in the AWS Console or by running:
Step 4: Push to AWS ECR 📤
-
Tag your Docker image:
-
Push to ECR:
Why Tag?
Tagging is like putting a shipping label on your container:
- Tells Docker where to send it
- Includes version information
- Makes it easy to find in ECR
Special Notes for M1/M2/M3 Mac Users 🍎
If you're using a newer Mac with Apple Silicon (M1, M2, or M3 chip):
-
Build for the right architecture:
-
Then continue with tagging and pushing as normal.
Why Different?
- New Macs use different processor architecture (ARM) than AWS (x86)
- We need to build specifically for AWS's architecture
- The
--platform
flag handles this for us
Troubleshooting 🔧
Common Docker Issues
-
Build Fails
- Check Dockerfile syntax
- Verify all files are present
- Look for Python dependency issues
-
Push Fails
- Check AWS credentials
- Verify repository exists
- Confirm login to ECR
-
Architecture Issues
- Use
--platform
flag on Apple Silicon - Check Docker Desktop settings
- Verify AWS region settings
- Use
Need Help?
- Review error messages carefully
- Check Docker logs
- See our Troubleshooting Guide
Success Criteria ✨
Your deployment is ready when:
- ✅ Docker image builds successfully
- ✅ Local container tests pass
- ✅ Image is pushed to ECR
- ✅ You can see your image in AWS Console
Next Steps 🎯
Now that your container is in ECR:
- Save your repository URI
- Keep your environment variables handy
- Get ready to set up your Lambda function!