Setting Up API Gateway
Time to connect your Lambda function to the internet! We'll start by creating the API Gateway trigger and then set up each endpoint.
Getting started: Create API Gateway Trigger 
First, create the API Gateway trigger from your Lambda function:
- Go to your Lambda function in AWS Console
- Click on the "Configuration" tab
- Select "Triggers" from the left menu
- Click "Add trigger"
-
In the trigger configuration:
- Select "API Gateway" from the dropdown
- Under "API", select "Create an API"
- Choose "HTTP API" (it's simpler and cheaper!)
- For "Security", select "Open"
-
Click "Add" to create the trigger
About HTTP APIs
HTTP APIs are perfect for our arcade because:
- They're cost-effective
- They're simpler to manage
- They have great performance
- They work well with Lambda
Creating Resources and Methods 
Step 1: Create a New Resource
- Click "Create resource" button
-
In the resource setup:
- Set Resource Path to "/" (root)
- Give your resource a name that matches an endpoint in your code
- Leave "Proxy Resource" and "CORS" unchecked
-
Click "Create resource"
Resource Names
Your resource name should match the endpoints in your code:
- /status
- /create-payment-link
- /addCredit
- /gameover
Step 2: Create and Configure Method
After creating your resource:
- Click on your newly created resource in the left sidebar
- Click "Create method" button
-
In the method setup:
- Choose the appropriate HTTP method (GET, POST) from dropdown
- Select "Lambda Function" for Integration type
- Enable "Lambda Proxy integration"
- Select your Lambda function from the dropdown
-
Click "Create method"
Important Settings
Make sure you:
- Choose the correct HTTP method for each endpoint
- Select Lambda Function integration type
- Enable Lambda Proxy integration
- Select your specific Lambda function
Step 3: Repeat for Each Endpoint
Create resources and methods for each endpoint:
-
Status Endpoint:
- Resource path: /status
- Method: GET
-
Payment Link Endpoint:
- Resource path: /create-payment-link
- Method: POST
-
Add Credit Endpoint:
- Resource path: /addCredit
- Method: POST
-
Game Over Endpoint:
- Resource path: /gameover
- Method: POST
Deploying Your API 
After creating all resources and methods:
- Click the "Deploy API" button
-
In the deployment popup:
- Select "[New Stage]" if this is your first deployment
- Enter a stage name (or leave as "default")
- Add a description if you want
-
Click "Deploy"
Get Your URL
After deployment, you'll get a URL that looks like:
Save this URL - you'll need it for:
- Testing your API
- Setting up Stripe webhooks
- Configuring your arcade cabinet
Testing Your Setup 
Test each endpoint using your new API URL:
1. Status Check
2. Payment Link Creation
curl -X POST https://your-api-url/create-payment-link \
-H "Content-Type: application/json" \
-d '{"machine_id":"test123"}'
3. Game Over Signal
curl -X POST https://your-api-url/gameover \
-H "Content-Type: application/json" \
-d '{"machine_id":"test123"}'
Troubleshooting 
Common issues and solutions:
Method Not Found
- Check that you created the resource correctly
- Verify HTTP method matches your code
- Ensure Lambda proxy integration is enabled
Lambda Permission Error
- Check that API Gateway has permission to invoke Lambda
- Verify Lambda function name is correct
- Review IAM roles and permissions
Deployment Issues
- Make sure all methods are properly configured
- Check that you've deployed to a stage
- Verify the API URL you're using matches your deployment stage
Need Help?
- Check Troubleshooting Guide
- Review CloudWatch logs
- Ask your teacher or mentor
Next Steps 
After deploying your API:
- Save your API URL
- Update Stripe webhook settings
- Test all endpoints
- Monitor for issues