echoing-zebra-28421
06/08/2021, 2:11 PMimport * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
// Look up an existing Lambda Function by ID, so that we can get its ARN. (If we knew the ARN ahead
// of time, this would not be necessary, we can just use it in the URI below.)
const handler = aws.lambda.Function.get("get-handler", "your_lambda_id");
// Define a GET endpoint that invokes our Lambda Function-based handler.
const api = new awsx.apigateway.API("example", {
swaggerString: handler.arn.apply(arn => JSON.stringify({
"swagger": "2.0",
"info": {
"title": "example",
"version": "1.0",
},
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"passthroughBehavior": "when_no_match",
"type": "aws_proxy",
"uri": `arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/${arn}/invocations`,
},
},
},
},
"x-amazon-apigateway-api-key-source": "HEADER",
"x-amazon-apigateway-binary-media-types": [ "*/*" ],
"x-amazon-apigateway-gateway-responses": {
"ACCESS_DENIED": {
"responseTemplates": {
"application/json": "{\"message\": \"404 Not found\" }",
},
"statusCode": 404,
},
"MISSING_AUTHENTICATION_TOKEN": {
"responseTemplates": {
"application/json": "{\"message\": \"404 Not found\" }",
},
"statusCode": 404,
},
},
})),
});
// Export the auto-generated AWS API Gateway base URL.
export const url = api.url;
brave-planet-10645
06/08/2021, 2:17 PM