https://pulumi.com logo
Title
e

echoing-zebra-28421

06/04/2021, 3:50 PM
Does anyone have an example where multiple routes from apigatewayv2 are implemented? for example:
const api = new awsx.apigateway.API(`airship-api-${NODE_ENV}`, {
  routes: [
    {
      path: "/",
      method: "GET",
      eventHandler: async (event: APIGatewayProxyEvent) => ({
        statusCode: HttpStatus.OK,
        body: "Hello, API Gateway V4!",
      }),
    },
    {
      path: "/api/named_users/associate",
      method: "POST",
      eventHandler: async (event: APIGatewayProxyEvent): Promise<any> => ({
        statusCode: HttpStatus.OK,
        body: JSON.stringify(await handleSetNamedUser(event)),
        isBase64Encoded: false,
      }),
    },
    {
      path: "/api/channels/tags",
      method: "POST",
      eventHandler: async (event: APIGatewayProxyEvent) => ({
        statusCode: HttpStatus.OK,
        body: JSON.stringify(await handleSetTags(event)),
        isBase64Encoded: false,
      }),
    },
  ],
});
I want to  make something if
w

witty-candle-66007

06/04/2021, 7:47 PM
The above code looks correct - so not sure what the question is?
e

echoing-zebra-28421

06/04/2021, 7:57 PM
I want to use aws.apigatewayv2.API. But can't find an example similar to awsx.apigateway.API
Looks like
routeKey
and
target
along with some lambda love are your friends.
e

echoing-zebra-28421

06/05/2021, 1:13 AM
I am trying to do this. But it seems that it is not right. Is there an example where you can guide me to make several routes and keep them in a single endpoint?
// Copyright 2016-2019, Pulumi Corporation.  All rights reserved.

import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import { getName } from "./utils";

const stack = pulumi.getStack();
const project = pulumi.getProject();
const nameBucket = `${getName(project, stack)}`;
// Create the role for the Lambda to assume
const lambdaRole = new aws.iam.Role(`${nameBucket}-role`, {
  assumeRolePolicy: {
    Version: "2012-10-17",
    Statement: [
      {
        Action: "sts:AssumeRole",
        Principal: {
          Service: "<http://lambda.amazonaws.com|lambda.amazonaws.com>",
        },
        Effect: "Allow",
        Sid: "",
      },
    ],
  },
});
// Attach the fullaccess policy to the Lambda role created above
const rolepolicyattachment = new aws.iam.RolePolicyAttachment(
  `${nameBucket}-role-policy-attachment`,
  {
    role: lambdaRole,
    policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole,
  }
);

// Create the namedUsersLambda to execute
const namedUsersLambda = new aws.lambda.Function(`${nameBucket}-namedUsers`, {
  code: new pulumi.asset.AssetArchive({
    ".": new pulumi.asset.FileArchive("./src/app/named-users"),
  }),
  runtime: "nodejs12.x",
  role: lambdaRole.arn,
  handler: "index.handler",
});
// Create the tagsLambda to execute
const tagsLambda = new aws.lambda.Function(`${nameBucket}-tags`, {
  code: new pulumi.asset.AssetArchive({
    ".": new pulumi.asset.FileArchive("./src/app/tags"),
  }),
  runtime: "nodejs12.x",
  role: lambdaRole.arn,
  handler: "index.handler",
});

// Give API Gateway lambdapermissionNamedUsers to invoke the Lambda
const lambdapermissionNamedUsers = new aws.lambda.Permission(
  `${nameBucket}-namedUsers`,
  {
    action: "lambda:InvokeFunction",
    principal: "<http://apigateway.amazonaws.com|apigateway.amazonaws.com>",
    function: namedUsersLambda,
  }
);
// Give API Gateway lambdapermissionTags to invoke the Lambda
const lambdapermissionTags = new aws.lambda.Permission(`${nameBucket}-tags`, {
  action: "lambda:InvokeFunction",
  principal: "<http://apigateway.amazonaws.com|apigateway.amazonaws.com>",
  function: tagsLambda,
});

// Set up the API Gateway
const apigwNamedUsers = new aws.apigatewayv2.Api(`${nameBucket}-namedUsers`, {
  protocolType: "HTTP",
  routeKey: "GET /named-users",
  target: namedUsersLambda.invokeArn,
});
// Set up the API Gateway
const apigwTags = new aws.apigatewayv2.Api(`${nameBucket}-tags`, {
  protocolType: "HTTP",
  routeKey: "GET /tags",
  target: tagsLambda.invokeArn,
});

export const endpointNamedUsers = apigwNamedUsers.apiEndpoint;
export const endpointTags = apigwTags.apiEndpoint;
c

curved-pharmacist-41509

06/05/2021, 1:17 AM
Put an answer in #typescript https://pulumi-community.slack.com/archives/CJ909TL6P/p1622855574044000?thread_ts=1622821601.043000&amp;cid=CJ909TL6P You need an integration + route to attach routes to your API gateway v2