Serverless-application-model: Dynamic URI in Swagger file

Created on 2 Feb 2017  路  6Comments  路  Source: aws/serverless-application-model

Hi,
Is there a way that I'm missing to have a more dynamic URI to the lambda function defined in a swagger file.

I've tried passing in region and arn/accountId variables in the same way that the function name is passed in in this example but it never works, even though I've confirmed that the variables contain the correct values.

The error I keep getting in the cloudformation console is

Errors found during import: Unable to put integration on 'GET' for resource at path '/preapproved-service/{service-name}': Invalid ARN specified in the request

Thanks for any advice

typquestion

Most helpful comment

+1, do we still have to in-line swagger?

All 6 comments

Unfortunately not. This is a API Gateway limitation and SAM does not have any control over it. You have to hard-code AccountId and Region in APIGateway until this limitation is fixed.

Is this changed yet ? I have the same issue.

I believe it's still the same. We've resorted to using inline swagger definitions being as our APIs are fairly simple.

@sanathkr Following the api_swagger_cors example (minus cors) I'm still seeing 'Invalid Arn' when creating the stack. Do we still need to hard code the account and region when using a separate swagger.yml file?

+1, do we still have to in-line swagger?

It seems swagger files referenced by DefinitionUri: still do not support substitution; neither !Sub or Fn::Sub: work, and AmazonApiGateway produces one of the following non-specific errors:

Errors found during import: Unable to put integration on 'GET' for resource at path '/foo': AWS ARN for integration must contain path or action (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ...)
Errors found during import: Unable to put integration on 'GET' for resource at path '/foo': Invalid ARN specified in the request



md5-2ad00d24a95900bed200c74168196125



Unable to parse API definition because of a malformed integration at path /foo. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ...)



md5-a4af4b89c36928d616ff541b52a8f6a8



        DefinitionBody:
          'Fn::Transform':
            Name: 'AWS::Include'
            # Replace <bucket> with your bucket name
            Parameters:
              Location: s3://<bucket>/swagger.yaml

and the accompanying example swagger.yaml contains substitutions which will be filled in with the relevant values.

EDIT: turns out @dinvlad posted about this here already https://github.com/awslabs/serverless-application-model/issues/8#issuecomment-290212883 see also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html

EDIT: see also https://github.com/aws/aws-cli/pull/3454 which (I think) enables this to work for local files by auto-uploading them to s3 first

Was this page helpful?
0 / 5 - 0 ratings