Setting Up AWS Lambda
Welcome to the AWS Lambda setup guide! Now that you have the Docker image on your computer, let's get it running in the cloud!
Prerequisites 
Before starting, make sure you have:
- Completed Basic AWS Setup
- Successfully pulled and renamed the Docker image (previous step)
- AWS CLI installed and configured
- Your terminal or PowerShell still open
Step 1: Push to Amazon ECR 
First, we need to get your Docker image into AWS's container registry (ECR):
-
Create an ECR repository:
-
Login to ECR (replace YOUR-REGION and YOUR-ACCOUNT-ID):
-
Tag your image for ECR (make sure to replace YOUR-REGION and YOUR-ACCOUNT-ID):
-
Push to ECR (using the same YOUR-REGION and YOUR-ACCOUNT-ID):
About YOUR-REGION and YOUR-ACCOUNT-ID
- Replace YOUR-REGION with values like
us-east-1
orus-west-2
- Replace YOUR-ACCOUNT-ID with your 12-digit AWS account number
- Find both values in the top right of your AWS Console
- Or run this command to find your account ID:
Command Example with Real Values
If your account ID is 123456789012 and region is us-east-1, your commands would look like:
Step 2: Create Lambda Function 
Now that your image is in ECR, let's create your Lambda function:
- Go to AWS Console
- Search for "Lambda"
- Click "Create function"
-
Choose these settings:
- Select "Container image"
- Set function name to "artcade-api"
- Click "Browse images"
- Select the "artcade-api-repo" repository
- Choose the "latest" tag
- Click "Create function"
What's Lambda?
AWS Lambda is like a smart worker in the cloud that:
- Runs your arcade payment code
- Only works when needed
- Automatically handles multiple players
- Stays within the free tier!
Step 3: Configure Environment 
Your Lambda function needs some secret information to work:
-
In Lambda Console:
- Click "Configuration" tab
- Select "Environment variables"
- Click "Edit"
-
Add these variables (you got these from previous setup steps):
STRIPE_API_KEY
: Your Stripe secret keySTRIPE_WEBHOOK_SECRET
: Your Stripe webhook secretMQTT_USERNAME
: Your EMQX usernameMQTT_PASSWORD
: Your EMQX passwordMQTT_BROKER
: Your EMQX broker addressMQTT_PORT
: Usually 8883 for SSL/TLSPRICE_ID
: Your Stripe Price ID
Keep Secrets Safe!
Never share these values with anyone! They're like the keys to your arcade's payment system.
Step 4: Test Your Function 
Let's make sure everything works:
- Click the "Test" tab
- Create new test event:
- Choose "API Gateway HTTP API" template
- Name it "TestEvent"
- Keep the default JSON
- Click "Test"
You should see a successful response!
Step 5: Monitor Your Function 
Set up basic monitoring:
- Go to "Monitor" tab
- View the CloudWatch metrics
- Note the "Invocations" and "Errors" graphs
Free Tier Limits
Your Lambda function gets:
- 1 million free requests per month
- 400,000 GB-seconds of compute time
- Plenty for several arcade cabinets!
Next Steps 
Your Lambda function is ready! Next, we'll:
- Set up API Gateway
- Connect it to your Lambda
- Test the complete system
Continue to API Gateway Setup โ Back to Docker Pull
Troubleshooting 
Common Issues
Push to ECR Failed
* Check AWS CLI configuration * Verify the repository name is exactlyartcade-api-repo
* Try logging in to ECR again
* Make sure you replaced YOUR-REGION and YOUR-ACCOUNT-ID
Lambda Creation Failed
* Verify your image URI is correct * Check IAM permissions * Confirm the image was pushed to ECR successfully * Make sure you're using the correct repository nameFunction Test Failed
* Check all environment variables are set correctly * Look at CloudWatch logs for specific error messages * Verify all secrets and credentials are correctNeed Help?
- Check our Troubleshooting Guide
- Ask your teacher or mentor
- Review CloudWatch logs in the "Monitor" tab