TMichel
TMichel

Reputation: 4452

Read AWS Region and AccountId from Swagger

How to get the AWS::Region and AWS::AccountId from a swagger file's x-amazon-apigateway-integration?

I tried many combinations following the docs, but no luck - always getting "Invalid ARN" when building the Cloudformation stack.

I was expecting to be able to do something like this in the swagger file:

x-amazon-apigateway-integration:
  uri:
    Fn::Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${stageVariables.myFunctionName}/invocations

However if I hardcode the Region and Account ids, it works:

x-amazon-apigateway-integration:
  uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:${stageVariables.myFunctionName}/invocations

Upvotes: 0

Views: 120

Answers (1)

Jason Wadsworth
Jason Wadsworth

Reputation: 8885

I have something like this that works.

  ApiGateway:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
      Body:
        openapi: 3.0.1
        paths:
          '/myGetEndpoint':
            get:
              x-amazon-apigateway-integration:
                uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:myLambdaFunction/invocations'

Upvotes: 1

Related Questions