https://pulumi.com logo
Title
c

clever-market-90633

02/02/2023, 5:15 PM
Hi, I'm really struggling to make an integration between AWS API Gateway and EventBridge, but I keep getting
API Gateway Integration: BadRequestException: Invalid ARN specified in the request
. Can anyone help me understand what am I doing wrong? This is the code:
const eventsResourcePOSTMethodIntegration = new aws.apigateway.Integration(
  "eventsResourcePOSTMethodIntegration",
  {
    restApi: restApi,
    resourceId: eventsResource.id,
    httpMethod: eventsResourcePOSTMethod.httpMethod,
    type: "AWS",
    credentials: apiGatewayRole.arn,
    passthroughBehavior: "NEVER",
    requestParameters: {
      "integration.request.header.X-Amz-Target": "'AWSEvents.PutEvents'",
      "integration.request.header.Content-Type": "'application/x-amz-json-1.1'"
    },
    uri: `arn:aws:apigateway:${region}:events:action/PutEvents`,
    integrationHttpMethod: "POST",
    requestTemplates: {
      "application/json": `#set($inputRoot = $input.path('$'))
      {
        "Entries": [
          #foreach($item in $inputRoot)
          {
            "Detail": $input.json("$[$foreach.index]"),
            "DetailType": "$item.eventType",
            "EventBusName": "test",
            "Source": "wrike.apigateway"
          }#if($foreach.hasNext),#end
        ]
      }
      #end`
    }
  },
  {
    dependsOn: [
      restApi,
      eventsResource,
      eventsResourcePOSTMethod,
      apiGatewayRole
    ]
  }
);
m

miniature-musician-31262

02/02/2023, 5:31 PM
Do you think it might be the
uri
property? Where is
${region}
coming from?
c

clever-market-90633

02/02/2023, 5:31 PM
Hi, It's comming from
const region = config.get("aws:region");
I`ve tried with and without
pulumi.interpolate
m

miniature-musician-31262

02/02/2023, 5:33 PM
We have a couple of examples of API Gateway-EventBridge integrations in our examples repository that you might find helpful for reference — one using API Gateway v1 and the other with Gateway v2: • https://github.com/pulumi/examples/tree/master/aws-ts-apigateway-eventbridgehttps://github.com/pulumi/examples/tree/master/aws-ts-apigatewayv2-eventbridge
Ok yeah, I’m pretty sure if you log out
region
, you’ll get something like
undefined
If you want that value, you’ll need to retrieve it a little differently. Lemme get you a doc.
There’s an example of fetching the AWS region name in that section
c

clever-market-90633

02/02/2023, 5:38 PM
I'll check that, but shouldn't
pulumi up
fail on other resources that use
region
too?
m

miniature-musician-31262

02/02/2023, 5:45 PM
The provider itself (
@pulumi/aws
) will generally read that value correctly, whether from your stack config file or from your shell environment, so your deployment will generally be fine. But if you want to use that value within your program code as well, you need to read it by passing the “namespace” (in this case
aws
) to a new Config instance and reading the
region
setting with that instance.
c

clever-market-90633

02/02/2023, 5:46 PM
Oh god... 4 hours on this. Chenged from
config.get
to
config.requeir
and
pulumi up
failed... thank you very much for the help
m

miniature-musician-31262

02/02/2023, 5:47 PM
Ah, great! So it hadn’t been set at all, looks like.
I think you’ll still get an
undefined
when you try to use it in a string (for that ARN), but you should be able to use the config thing I mentioned to address that.
Hopefully those two end-to-end examples will help as well.
c

clever-market-90633

02/02/2023, 5:51 PM
Ok, I think I`ll advance on this now, always hard at the beginning. I`ll read the resources and try to get it done. Thanks again
m

miniature-musician-31262

02/02/2023, 5:59 PM
You bet! Best of luck.