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

Api Gateway Deployment not updated when AutoPublishAlias is changed #1547

Closed
zroger opened this issue Mar 31, 2020 · 3 comments
Closed

Api Gateway Deployment not updated when AutoPublishAlias is changed #1547

zroger opened this issue Mar 31, 2020 · 3 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... stage/bug-repro The issue/bug needs to be reproduced type/bug

Comments

@zroger
Copy link

zroger commented Mar 31, 2020

Description:

When changing the value of AutoPublishAlias on a function resource, the new alias was created, the old alias deleted, and the associated API Gateway resources were updated. However, a new deployment was not created, leaving the API Gateway stage pointed at the previous function alias.

This seems to be only a problem when using inline swagger.

Steps to reproduce the issue:

  1. Starting from the inline_swagger example, add an AutoPublishAlias with the value v1 to the function resource, and change the reference in the swagger to ${MyLambdaFunction.Alias}.
  2. Deploy this template to a new stack.
  3. Update the value of the AutoPublishAlias property to v2.
  4. Create a new changeset.

Observed result:
The created changeset contains the following:

  • Modify the MyApi AWS::ApiGateway::RestApi resource
  • Modify the MyLambdaFunctionGetApiPermissionprod AWS::Lambda::Permission resource
  • Add the MyLambdaFunctionAliasv2 AWS::Lambda::Alias resource
  • Remove the MyLambdaFunctionAliasv1 AWS::Lambda::Alias resource.

Expected result:
A changeset that also creates a new deployment resource and updates the stage.

@jfuss
Copy link
Contributor

jfuss commented Jul 6, 2022

The cause of this is in how SAM generates the logical id for the API Gateway Deployment resource. This is done by hashing the inline swagger that is generated or provided which does not resolve all the intrinsics, since SAM relies on CloudFormation to do that after SAM is done.

Doing this now automatically is problematic as it will create redeployment for customers. Maybe that is the right thing here but we need to make sure we don't cause issues for customers when this happens. In the past (for similar things like Layers), we have caused stacks to get into un-deployable state due to throttling caused by to many updates at once. So we would need to be cautious here. Maybe we need to create a new property to make it opt in, but to solve this we either need to find a way to generate new logical ids for cases like this or resolve intrinsics. Generally/historically, we have shy'ed away from resolving intrinsics as this causes us to re-implement CloudFormation and would need to keep up to date with new ones.

@hoffa
Copy link
Contributor

hoffa commented Oct 17, 2022

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 #2533 for more information.

@hoffa
Copy link
Contributor

hoffa commented Nov 3, 2022

Closing in favor of #2533.

@hoffa hoffa closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... stage/bug-repro The issue/bug needs to be reproduced type/bug
Projects
None yet
Development

No branches or pull requests

6 participants