Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::Serverless::Api deployment resource is not generated on Sub'ed Ref change #914

Closed
tommyvn opened this issue May 13, 2019 · 1 comment

Comments

@tommyvn
Copy link

tommyvn commented May 13, 2019

  1. Deploy the attached Cloudformation template, see that visiting the API GW address shows the text in the RandomParameter CF parameter.
  2. Update the stack and change the RandomParameter value, see that a new Deployment resource is not created by the Serverless transform and see that visiting the API GW address shows the previous value of RandomParameter rather than the expected current one.

Thinking about this in the context of my own custom transform I get why detecting the change in the ref is difficult in a transform, with it being a layer removed, but the UX confused me, my VTL changed so why didn't it deploy was my initial reaction.

I suspect this suggestion won't fly but I'm making it anyway: could you generate a new Deployment on every transform regardless of if the Api resource has changed or not? It feels like a safe choice, worst case it's a noop deployment, best case it means !Refs and !Subs and !Ifs within the transformed resource work intuitively.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
  RandomParameter:
    Type: String

Resources:
  Api:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: '2.0'
        schemes:
        - https
        paths:
          "/":
            get:
              consumes:
              - application/json
              produces:
              - text/html
              responses:
                '200':
                  description: Successful operation
                  headers:
                    Content-Type:
                      type: string
              x-amazon-apigateway-integration:
                responses:
                  default:
                    statusCode: '200'
                    responseParameters:
                      method.response.header.Content-Type: "'text/html'"
                    responseTemplates:
                      text/html: !Sub |-
                        <html>
                            <body>
                                <h1>${RandomParameter}</h1>
                            </body>
                        </html>
                passthroughBehavior: when_no_match
                requestTemplates:
                  application/json: '{"statusCode": 200}'
                type: mock

Outputs:
  Url:
    Value: !Sub https://${Api}.execute-api.${AWS::Region}.amazonaws.com/Prod
@praneetap
Copy link
Contributor

This is similar to issue #479. SAM only generates a new API Gateway Deployment if the swagger definition changes. If SAM uses an intrinsic function inside the swagger definition, the definition is not seen as changed, even if the value returned by the intrinsic function changes.
One way to workaround this (and force redeployment) is to make a change in the swagger.

This isn't ideal, and we are aware of this issue. Please +1 on #479 to help prioritize this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants