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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With