Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to specify x-amazon-apigateway-integration uri with Sub function

Tags:

aws-sam

I have a swagger.yaml file with the following:

paths:
  /path/endpoint:
    post:
      ...
      x-amazon-apigateway-integration:
        uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"

When I try to deploy this with the sam cli I get the error "AWS ARN for integration must contain path or action" in CloudFormation.

However, if I hardcode the AWS::Region value and MyFunction.Arn, I do not get the error.

Does anyone know why the Sub function is not working for the uri?

like image 552
mark Avatar asked Jan 23 '26 20:01

mark


2 Answers

Yes, you need to format your integration path like this when using yaml format for the swagger yaml:

x-amazon-apigateway-integration:
    uri:
      Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"

The short form (for sub, "!Sub") which you are using will give you problems. You need to use the long form, Fn::Sub If you are working with SAM I also reccomend you review the AWS documentation on intrinsic functions, especially using Sub in conjuction with Imports. Hope this helps.

like image 200
Shravan Deolalikar Avatar answered Jan 26 '26 23:01

Shravan Deolalikar


Shravan mentioned half of the problem. The other thing you need to do is use "DefinitionBody" and "Fn::Transform", as shown below, when adding your swagger file to your template or the variables in your swagger file will not be substituted.

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: my-api
      StageName: dev
      DefinitionBody:
        'Fn::Transform':
          Name: 'AWS::Include'
          Parameters:
            Location: s3://my-api/swagger.yaml

Simply using "DefinitionUri" to specify your swagger file will not work.

# This will cause the variables in your swagger file to not be substituted. You must use the format above to get variables to work in your swagger file.
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: my-api
      StageName: dev
      DefinitionUri: swagger.yaml

Unfortunately this also means you need to specify the full s3 path to your swagger file and upload it to S3 before deploying your SAM. See: https://github.com/awslabs/serverless-application-model/issues/305

like image 23
mark Avatar answered Jan 27 '26 00:01

mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!