Lambda-backed API Gateway using Crosswalk
ADD
aws-ts-apigateway-lambda-serverless/.gitignore
+/bin/
+/node_modules/

ADD
aws-ts-apigateway-lambda-serverless/Pulumi.yaml
+name: aws-ts-apigateway-lambda-serverless
+runtime: nodejs
+description: Creates a serverless application using API Gateway backed by lambda functions

ADD
aws-ts-apigateway-lambda-serverless/handler.ts
+'use strict'
+
+import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
+import * as aws from '@pulumi/aws';
+
+/**
+ * A simple function that returns the request.
+ *
+ * @param {APIGatewayProxyEvent} event -
+ * @returns returns a confirmation to the message to the
+ */
+export const handler: aws.lambda.EventHandler<APIGatewayProxyEvent, APIGatewayProxyResult> = async (event) => {
+ const route = event.pathParameters!["route"];
+ const body = event.body ? JSON.parse(event.body) : null;
+
+ console.log('Received body: ', body);
+
+ return {
+ statusCode: 200,
+ body: JSON.stringify({
+ route,
+ affirmation: "Nice job, you've done it! :D",
+ requestBodyEcho: body
+ })
+ }
+}
+
+export default handler;
\ No newline at end of file

ADD
aws-ts-apigateway-lambda-serverless/index.ts
+import * as awsx from "@pulumi/awsx";
+import handler from './handler';
+
+/**
+ * api-gatewayx https://www.pulumi.com/docs/guides/crosswalk/aws/api-gateway/
+ */
+
+// Create an API endpoint.
+let endpoint = new awsx.apigateway.API("hello-world", {
+ routes: [
+ {
+ path: "/{route+}",
+ method: "GET",
+ // Functions can be imported from other modules
+ eventHandler: handler
+ },
+ {
+ path: "/{route+}",
+ method: "POST",
+ // Functions can be created inline
+ eventHandler: (event) => {
+ console.log('Inline event handler');
+ console.log(event);
+ }
+ },
+ {
+ path: "/{route+}",
+ method: "DELETE",
+ // Functions can be created inline
+ eventHandler: (event) => {
+ console.log('Inline delete event handler');
+ console.log(event);
+ }
+ },
+ ],
+});
+
+// Pulumi exports values
+// See these outputs using: pulumi stack output endpointUrl
+export const endpointUrl = endpoint.url;
\ No newline at end of file

ADD
aws-ts-apigateway-lambda-serverless/package.json
+{
+ "name": "aws-ts-apigateway-lambda-serverless",
+ "devDependencies": {
+ "@types/aws-lambda": "^8.10.72",
+ "@types/node": "^10.0.0"
+ },
+ "dependencies": {
+ "@pulumi/aws": "^3.25.1",
+ "@pulumi/awsx": "^0.24.0",
+ "@pulumi/pulumi": "^2.0.0"
+ }
+}

ADD
aws-ts-apigateway-lambda-serverless/tsconfig.json
+{
+ "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"
+ ]
+}

Lambda-backed API Gateway using Crosswalk