AWS — API Gateway
What is API Gateway?
Managed service for creating, publishing, and securing APIs.
Create REST API
aws apigateway create-rest-api --name my-api
Create resource
aws apigateway create-resource \
--rest-api-id abc123 \
--parent-id root \
--path-part items
Create method
aws apigateway put-method \
--rest-api-id abc123 \
--resource-id xyz789 \
--http-method GET \
--authorization-type NONE
Lambda integration
aws apigateway put-integration \
--rest-api-id abc123 \
--resource-id xyz789 \
--http-method GET \
--type AWS_PROXY \
--integration-http-method POST \
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:my-function/invocations
Deploy API
aws apigateway create-deployment \
--rest-api-id abc123 \
--stage-name prod
Stages
# Create stage
aws apigateway create-stage \
--rest-api-id abc123 \
--stage-name dev \
--deployment-id deploy123
# Enable caching
aws apigateway update-stage \
--rest-api-id abc123 \
--stage-name prod \
--patch-operations op=replace,path=/cacheClusterEnabled,value=true
Usage plans
aws apigateway create-usage-plan \
--name basic-plan \
--throttle burstLimit=10,rateLimit=5
Best practices
- Use API keys for tracking
- Enable caching
- Set up usage plans
- Enable logging
Mini Practice
- Create a REST API
- Integrate with Lambda
- Deploy to a stage
- Set up API keys
Up Next
Continue with ElastiCache - Caching.
Related Topics
Frequently Asked Questions about API Gateway
What is API Gateway in AWS?
API Gateway is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn API Gateway?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn API Gateway.
Why is API Gateway important in AWS?
API Gateway is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.