API GateWay and Lambda
flowchart LR;
subgraph protected
A[API GateWay]-->B[Lambda]
end
C[API Key]-->protected
- Create Lambda. Test by,
## event.json
{
"queryStringParameters": {
"transactionId": "value1",
"type": "value2",
"amount": "value3"
}
}
##
aws-vault exec leo.leung -- aws lambda invoke --region=eu-west-2 --function-name=func2 response.json --payload file://event.json
## it should respond with response.json
{"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": "{\"transactionId\":
\"value1\", \"type\": \"value2\",
\"amount\": \"value3\",
\"message\": \"Hello from Lambda land\"}"}%
##
- Create API Gateway.
- Configure Gateway, like add resource, add method, deploy.
- Test by Postman, or browser.
https://xxxxxx.execute-api.eu-west-2.amazonaws.com/v1/predict?transactionId=1234&type=buy&amount=300
- Configure Gateway, method execution → api key required → api keys → Usage Plans.
- Test by Postman by including header x-api-key.
References
- API Authentication via API Keys | AWS API Gateway
- AWS API Gateway to Lambda Tutorial in Python | Build a REST API
- Invoke Lambda Functions with AWS CLI - Complete Guide