Problem: Frontend, DB is ready, but need a method to connect
Solution: API Gateway as front door of the app+ Lambda to process data
How to link lambda with API Gateway?
Lambda Proxy Integration, a feature of API Gateway, allows client to call a single lambda function in the backend,which can call other lambda functions or AWS services or resources
Amazon API Gateway Stages
Amazon API Gateway - Versioning Deployment Strategies Overview
Microservices
Summary:
Create Lambda function
Create API Gateway - RESTful API
Important Notes:
Lambda Test event choose - API Gateway AWS Proxy template
Serialize python JSON with response_payload function,
````
response = response_payload(err, response_body)
return response
'''
In Lambda proxy integration, API Gateway sends the entire request as input to a backend Lambda function.
API Gateway then transforms the Lambda function output to a frontend HTTP response.
Output Format: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
'''
def response_payload(err, res=None):
return {
'statusCode': '400' if err else '200',
'body': err if err else json.dumps(res),
'headers': {
'Content-Type': 'application/json',
},
}
```
Step for API Gateway + Lambda
3.1) Create Resources, with name pets
3.2) Create Method, check lambda proxy integration (Send the request to your Lambda function as a structured event), and select lambda
3.3) To create /{id} path, click on resources route /pets, and click ‘Create resource’, then Resource name == {id}
3.4) On method, select same method as 3.2
3.5) Go to test tab, add 1 as id and test it.
On Lambda Test event, you configure resource and pathParameters key. I.e.
"resource": "/pets/{id}"
"pathParameters": {
"id": 1
}
Then in Lambda, it’s filtered like