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

AutoPublishAlias not updating version when using FindInMap function in CodeUri.Key #3414

Closed
smathez opened this issue Nov 13, 2023 · 4 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ...

Comments

@smathez
Copy link

smathez commented Nov 13, 2023

Description

The alias/version won't update when using lambda code packaged as zip files stored on an S3 bucket, and use FindInMap function for CodeUri.Key. (For greater readability of our templates, the versions are defined in Mappings, and we refer to them using the FindInMap function.)

Example of template:

AWSTemplateFormatVersion: '2010-09-09'
Transform:
    - AWS::Serverless-2016-10-31
Description: XXX
Mappings:
    Lambdas:
        authorizer:
            package: ecs-commons-lambda-authorizer-1.3.0
        mpf:
            package: ecs-mpf-lambda-1.2.4
...
Globals:
    Function:
        Runtime: nodejs18.x
        AutoPublishAlias: live
        Tracing: Active
        CodeUri:
            Bucket: !Ref lambdaS3Bucket
...
    MpfTriggerFunction:
        Type: AWS::Serverless::Function
        Properties:
            Handler: index.handler
            CodeUri:
                Key: !FindInMap [Lambdas, mpf, package]
            FunctionName: 'xxx-eventTrigger'
            Events:
                MpfEvent:
                    Type: EventBridgeRule
                    Properties:
                        EventBusName: eventBusXXX
                        Pattern:
                            detail-type:
                                - prefix: 'XXX/'

If I change the package in the mapping, lambda function is updated but not my alias/version, so the event rule is always pointing to the previous version :

-------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                               LogicalResourceId                       ResourceType                            Replacement                           
-------------------------------------------------------------------------------------------------------------------------------------------------------------
* Modify                                MpfTriggerFunctionRole                  AWS::IAM::Role                          False                                 
* Modify                                MpfTriggerFunction                      AWS::Lambda::Function                   False                                 
-------------------------------------------------------------------------------------------------------------------------------------------------------------

But if I don't use the mapping anymore and update the CodeUri.Key part like that, everything is working fine :

    MpfTriggerFunction:
        Type: AWS::Serverless::Function
        Properties:
            Handler: index.handler
            CodeUri:
                Key: ecs-mpf-lambda-1.2.5
CloudFormation stack changeset
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                               LogicalResourceId                       ResourceType                            Replacement                           
-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add                                   MpfTriggerFunctionVersione5e43cd2e8     AWS::Lambda::Version                    N/A                                   
* Modify                                MpfTriggerFunctionAliaslive             AWS::Lambda::Alias                      False                                 
* Modify                                MpfTriggerFunction                      AWS::Lambda::Function                   False                                 
- Delete                                MpfTriggerFunctionVersion5a618a3a55     AWS::Lambda::Version                    N/A                                   
-------------------------------------------------------------------------------------------------------------------------------------------------------------

Additional environment details

  1. OS: Linux
  2. SAM CLI 1.101.0
  3. AWS region: eu-west-1
@smathez smathez added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Nov 13, 2023
@aaythapa
Copy link
Contributor

Hi @smathez on the first look, this seems like an intrinsic issue. Our recommendation for intrinsic issues is to use AWS::LanguageExtensions (more info in #2533). We tested with the language extensions and it seems to work

@GavinZZ
Copy link
Contributor

GavinZZ commented Nov 14, 2023

Just to be clear, you could use additional transform like this.

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

@GavinZZ GavinZZ added area/intrinsics Ref, If, Sub, GetAtt, ... and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 14, 2023
@aaythapa
Copy link
Contributor

Closing this issue for now, please re-open if the issue persists

@nguyinh
Copy link

nguyinh commented Dec 7, 2023

Hi,
Following your advices and adding - AWS::LanguageExtensions works on some deployments but randomly some deployments fail with the following error :
Resource handler returned message: "Version already exists: [arn:aws:lambda:eu-west-1:123456789012:function:lambda-xxx:7]
We can focus on the context provided by @smathez, it is the same environnement and SAM content

Eventually this error disappear for some coworkers when they try to deploy the same SAM multiple times, but we cannot just pray that it will work on our production environnement

Do you have some information on this behavior ?
Thanks for your insights !

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, ...
Projects
None yet
Development

No branches or pull requests

4 participants