AWS API Gateway V2 HTTP API quickstart
Quickstart example of using AWS API Gateway v2 HTTP API
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-py-apigatewayv2-http-api-quickcreatecd pulumi-examples/aws-py-apigatewayv2-http-api-quickcreateSet up a simple HTTP API using AWS API Gateway V2. The API executes a simple Lambda function found in /app/index.js.
Prerequisites#
Deploying the example#
Note: some values in this example will be different from run to run. These values are indicated with ***.
-
Create a new stack:
Terminal window pulumi stack init http-api -
Set the AWS region to deploy into:
Terminal window pulumi config set aws:region us-east-2 -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Run
pulumi upto preview and deploy changes:Terminal window pulumi upPreviewing update (http-api)...Updating (http-api)Type Name Status+ pulumi:pulumi:Stack aws-py-apigatewayv2-quickstart-http-api created+ ├─ aws:iam:Role lambdaRole created+ ├─ aws:lambda:Function lambdaFunction created+ ├─ aws:iam:RolePolicyAttachment lambdaRoleAttachment created+ ├─ aws:apigatewayv2:Api httpApiGateway created+ └─ aws:lambda:Permission lambdapermission createdOutputs:endpoint: "https://***.execute-api.us-east-2.amazonaws.com"Resources:+ 6 createdDuration: 22s -
View the endpoint URL and curl a few routes:
Terminal window pulumi stack outputCurrent stack outputs (1):OUTPUT VALUEendpoint https://***.execute-api.us-east-2.amazonaws.comTerminal window curl $(pulumi stack output endpoint)Hello, Pulumi! -
To view the runtime logs of the Lambda function, use the
pulumi logscommand. To get a log stream, usepulumi logs --follow. -
At this point, you have a running HTTP API. Feel free to modify your program, and run
pulumi upto redeploy changes. The Pulumi CLI automatically detects what has changed and makes the minimal edits necessary to accomplish these changes. This could be altering the function used by the Lambda, or anything else you’d like!
Cleaning up#
-
Run
pulumi destroyto 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.
