serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Feature Request: Redeploy AWS::Serverless::Api after updating a referenced parameter or metadata attribute

Open atakidev opened this issue 6 years ago • 3 comments

Description:

When AWS::Serverless::Api is used, AWS::ApiGateway::Deployment, AWS::ApiGateway::Stage are generated as described below.

  • https://github.com/awslabs/serverless-application-model/blob/develop/versions/2016-10-31.md#referencing-generated-resources---stage--deployment
SAM will generate an API Gateway Stage and API Gateway Deployment for every AWS::Serverless::Api resource.

SAM regenerates Deployment and Stage resources after updating a swagger definition. It usually works well.

However, when I use !Ref to reference a parameter in swagger definition, AWS::Serverless::Api doesn't generate Deployment and Stage resources again after updating the parameter only.

For example, the following !Ref ParamValue and updating ParamValue, the change doesn't re-generate Deployment and Stage.

Parameters:
  ParamValue:
    Type: String

Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: ApiGatewayName
      StageName: Prod
      Cors: "'www.example.com'"
      DefinitionBody:
        swagger: 2.0
        basePath: /prod
        info:
          title: AwsSamExample2
          description: !Ref ParamValue
        schemes:
        - https
        paths:
          /:
            x-amazon-apigateway-any-method:

... snip ...

We may confuse there are the difference between updating parameters and editing swagger definition.

Personally, I think it is good to handle updating referenced parameters can also update Deployment and Stage resources. Or, I think it is also good to check Metadata attribute of AWS::Serverless::Api because customer can forcefully update the resource like other CloudFormation resources described in the following page.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html#troubleshooting-errors-no-updates-to-perform

If you need to make such changes without making any other change, you can add or modify a metadata attribute for any of your resources.

Please let me know if you have any questions.

atakidev avatar May 31 '20 12:05 atakidev

+1 This is a problem I've encountered recently as well.

justinmclark avatar Feb 10 '22 22:02 justinmclark

You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

See https://github.com/aws/serverless-application-model/issues/2533 for more information.

hoffa avatar Oct 17 '22 21:10 hoffa

Closing in favor of https://github.com/aws/serverless-application-model/issues/2533.

hoffa avatar Nov 03 '22 23:11 hoffa