https://pulumi.com logo
Title
h

hallowed-mouse-70261

02/15/2021, 7:46 PM
Hey all, I'm running into an issue using the automation-api with api-gateway and lambda. In pulumiProgram(), I'm creating a gateway like so:
const gateway = new awsx.apigateway.API(
    `my-lambda-gateway`,
    {
      routes: [
        {
          path: '/myLambdaFunction',
          method: 'POST',
          eventHandler: myLambdaFunction
        }
      ]
    }
  );
and get the error:
Diagnostics:
  pulumi:pulumi:Stack (my-stack-development):
    error: update failed
 
  aws:apigateway:RestApi (my-lambda-gateway):
    error: 1 error occurred:
        * creating urn:pulumi:development::my-stack::aws:apigateway:x:API$aws:apigateway/restApi:RestApi::my-lambda-gateway: 1 error occurred:
        * error creating API Gateway specification: BadRequestException: Errors found during import:
        Unable to put integration on 'POST' for resource at path '/myLambdaFunction': Invalid ARN specified in the request
This is odd because I can confirm that
myLambdaFunction
does in fact have a valid arn that is currently working on an api-gateway set up outside of this test in the same way. Any ideas?
g

gifted-terabyte-92288

02/15/2021, 10:39 PM
@brave-planet-10645 👋 Have you ever seen or run into the above? Currently blocking us 😕
b

brave-planet-10645

02/16/2021, 9:24 AM
Can you provide the code for
myLambdaFunction
please?
I've just put together a quick demo that you can take a look at here: https://github.com/pierskarsenbarg/pulumi-scratchpad/tree/main/apigatewaylambda
That works for me
The main part is in the index.ts file
h

hallowed-mouse-70261

02/16/2021, 2:59 PM
thanks! I'll check it out and tell you if my version works with your example
Hey, so using you're example I'm still getting the same error. Here's the code:
import { LocalWorkspace } from '@pulumi/pulumi/x/automation';
import * as aws from '@pulumi/aws';
import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';

export async function standup(): Promise<void> {
  const pulumiProgram = async (): Promise<any> => {
    const role = new aws.iam.Role('ruleReportsFuncRole', {
      assumeRolePolicy: {
        Version: '2012-10-17',
        Statement: [
          {
            Action: 'sts:AssumeRole',
            Principal: {
              Service: '<http://lambda.amazonaws.com|lambda.amazonaws.com>'
            },
            Effect: 'Allow',
            Sid: ''
          }
        ]
      }
    });

    const rolePolicyAttachment = new aws.iam.RolePolicyAttachment('rpa', {
      policyArn: aws.iam.ManagedPolicy.LambdaFullAccess,
      role: role
    });

    const lambdaFunction = new aws.lambda.Function('lambdafunction', {
      code: new pulumi.asset.AssetArchive({
        '.': new pulumi.asset.FileArchive('./app')
      }),
      role: role.arn,
      handler: 'index.lambdaCode',
      runtime: 'nodejs14.x'
    });

    const gateway = new awsx.apigateway.API(`my-lambda-gateway`, {
      routes: [
        {
          path: '/myLambdaFunction',
          method: 'POST',
          eventHandler: lambdaFunction
        }
      ]
    });

    return {
      url: gateway.url
    };
  };

  const args = {
    stackName: `myCompany/development-myusername-integration-my-lambda`,
    projectName: 'myCompany-my-project',
    program: pulumiProgram,
    workDir: '.'
  };

  const stack = await LocalWorkspace.createOrSelectStack(args);
  await stack.workspace.installPlugin('aws', 'v3.6.1');
  await stack.setConfig('aws:region', { value: 'us-east-2' });
  await stack.refresh({ onOutput: <http://console.info|console.info> });
  await stack.up({ onOutput: <http://console.info|console.info> });
}
and here's the error:
Diagnostics:
  pulumi:pulumi:Stack (myCompany-my-project-development-myusername-integration-my-lambda):
    error: update failed
 
  aws:apigateway:RestApi (my-lambda-gateway):

    error: 1 error occurred:
        * creating urn:pulumi:development-myusername-integration-my-lambda::myCompany-my-project::aws:apigateway:x:API$aws:apigateway/restApi:RestApi::my-lambda-gateway: 1 error occurred:
        * error creating API Gateway specification: BadRequestException: Errors found during import:
        Unable to put integration on 'POST' for resource at path '/myLambdaFunction': Invalid ARN specified in the request
    error: post-step event returned an error: failed to verify snapshot: resource urn:pulumi:development-myusername-integration-my-lambda::myCompany-my-project::aws:apigateway:x:API$aws:apigateway/restApi:RestApi::my-lambda-gateway dependency  refers to missing resource
b

brave-planet-10645

02/17/2021, 2:27 PM
Sorry, I missed that you're using automation api. There is a bug when using apigateway from awsx and automation api: https://github.com/pulumi/pulumi/issues/6162
In fact, it was opened by @gifted-terabyte-92288 by the looks of things
g

gifted-terabyte-92288

02/17/2021, 2:29 PM
Yeah - looks to be a similar issue. Thank you for the help, Piers.