Try AWS Native preview for resources not in the classic version.
Lambda-backed API Gateway
Try AWS Native preview for resources not in the classic version.
This example provides API endpoints which are executed by AWS Lambda using Python. The example sets up up two Lambda-backed API Gateways: an API Gateway V1 (REST) and an API Gateway V2 (HTTP). AWS provides some information on the differences between these two API Gateway types: Announcing HTTP APIs for Amazon API Gateway and API Gateway V2 FAQs
This sample uses the following AWS products:
- Amazon API Gateway is used as an API proxy
- AWS Lambda is used to process API events by executing typescript/javascript code
Prerequisites
Create a new stack:
$ pulumi stack init aws-py-apigateway-lambda-serverless
Set the AWS region:
$ pulumi config set aws:region us-east-2
Deploy the App
Run
pulumi up
to preview and deploy changes:To view the runtime logs of the Lambda function, use the
pulumi logs
command. To get a log stream, usepulumi logs --follow
.
Test the Endpoints
Use a HTTP tool like curl
or httpie
(pip3 install httpie
) to query the API Gateway endpoints using the Pulumi stack outputs.
Example using curl
:
curl $(pulumi stack output apigateway-rest-endpoint)
curl $(pulumi stack output apigatewayv2-http-endpoint)
Example using httpie
:
http $(pulumi stack output apigateway-rest-endpoint)
http $(pulumi stack output apigatewayv2-http-endpoint)
Output should include "Cheers from AWS Lambda!!"
.
Clean Up
Run
pulumi destroy
to tear down all resources.To delete the stack itself, run
pulumi stack rm
. Note that this command deletes all deployment history from the Pulumi console.
Summary
In this tutorial, you built a lambda-backed API on AWS using API Gateway, lambda functions, and Pulumi. This serverless solution is highly scaleable, resilient, and stateless.
Next Steps
Try AWS Native preview for resources not in the classic version.