forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added quickstart version of apigatewayv2 http api (pulumi#862)
* Added quickstart version of apigatewayv2 http api * Fixing lint errors * Fixed linting * Moved folder to be more descriptive * Renamed pulumi project * Update index.ts * Update README.md * Update README.md * Updated README * Fixing linting
- Loading branch information
1 parent
695da88
commit 1990689
Showing
9 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: aws-ts-apigatewayv2-http-api-quickstart | ||
runtime: nodejs | ||
description: Quickstart example of using AWS API Gateway v2 HTTP API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# AWS API Gateway V2 HTTP API Quickstart | ||
|
||
Set up a simple HTTP API using AWS API Gateway V2 | ||
|
||
## Deploying and running the program | ||
|
||
Note: some values in this example will be different from run to run. These values are indicated | ||
with `***`. | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
$ pulumi stack init http-api | ||
``` | ||
|
||
1. Set the AWS region: | ||
|
||
``` | ||
$ pulumi config set aws:region us-east-2 | ||
``` | ||
|
||
1. Restore NPM modules via `npm install` or `yarn install`. | ||
|
||
1. Run `pulumi up` to preview and deploy changes: | ||
|
||
``` | ||
$ pulumi up | ||
Previewing update (http-api) | ||
... | ||
|
||
Updating (http-api) | ||
|
||
Type Name Status | ||
+ pulumi:pulumi:Stack aws-ts-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 created | ||
|
||
Outputs: | ||
endpoint: "https://****.execute-api.us-east-2.amazonaws.com" | ||
|
||
Resources: | ||
+ 6 created | ||
|
||
Duration: 22s | ||
``` | ||
|
||
1. View the endpoint URL and curl a few routes: | ||
|
||
```bash | ||
$ pulumi stack output | ||
Current stack outputs (1): | ||
OUTPUT VALUE | ||
endpoint https://***.execute-api.us-east-2.amazonaws.com | ||
$ curl $(pulumi stack output endpoint) | ||
Hello, Pulumi! | ||
``` | ||
|
||
1. To view the runtime logs of the Lambda function, use the `pulumi logs` command. To get a log stream, use `pulumi logs --follow`. | ||
|
||
## Clean up | ||
|
||
1. Run `pulumi destroy` to tear down all resources. | ||
|
||
1. To delete the stack itself, run `pulumi stack rm`. Note that this command deletes all deployment history from the Pulumi Console. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports.handler = async function(event, context) { | ||
console.log("EVENT: \n" + JSON.stringify(event, null, 2)) | ||
return { | ||
statusCode: 200, | ||
body: "Hello, Pulumi!" | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. All rights reserved. | ||
|
||
import * as aws from "@pulumi/aws"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
// Create the role for the Lambda to assume | ||
const lambdaRole = new aws.iam.Role("lambdaRole", { | ||
assumeRolePolicy: { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Action: "sts:AssumeRole", | ||
Principal: { | ||
Service: "lambda.amazonaws.com", | ||
}, | ||
Effect: "Allow", | ||
Sid: "", | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
// Attach the fullaccess policy to the Lambda role created above | ||
const rolepolicyattachment = new aws.iam.RolePolicyAttachment("lambdaRoleAttachment", { | ||
role: lambdaRole, | ||
policyArn: aws.iam.ManagedPolicies.AWSLambdaFullAccess, | ||
}); | ||
|
||
// Create the Lambda to execute | ||
const lambda = new aws.lambda.Function("lambdaFunction", { | ||
code: new pulumi.asset.AssetArchive({ | ||
".": new pulumi.asset.FileArchive("./app"), | ||
}), | ||
runtime: "nodejs12.x", | ||
role: lambdaRole.arn, | ||
handler: "index.handler", | ||
}); | ||
|
||
// Give API Gateway permissions to invoke the Lambda | ||
const lambdapermission = new aws.lambda.Permission("lambdaPermission", { | ||
action: "lambda:InvokeFunction", | ||
principal: "apigateway.amazonaws.com", | ||
function: lambda, | ||
}); | ||
|
||
// Set up the API Gateway | ||
const apigw = new aws.apigatewayv2.Api("httpApiGateway", { | ||
protocolType: "HTTP", | ||
routeKey: "GET /", | ||
target: lambda.invokeArn, | ||
}); | ||
|
||
export const endpoint = apigw.apiEndpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "aws-ts-apigatewayv2-quickstart", | ||
"devDependencies": { | ||
"@types/node": "^10.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^3.0.0", | ||
"@pulumi/awsx": "^0.22.0", | ||
"@pulumi/pulumi": "^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |