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

Lambda layer code not updated in Lambda function during sam sync #3632

Closed
niklas-palm opened this issue Aug 6, 2024 · 1 comment
Closed
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@niklas-palm
Copy link

Description

When using sam sync for updating a Lambda Layer written in typescript, the change is not reflected in the imported code in the lambda function.

Referencing a LambdaLayer in a Lambda function, I'm expecting the lambda function to use the updated layer during invocation. This is the observed bahaviour using python, but when using a Typescript layer together with sam sync, the change is not propagated to the live function, despite the SAM cli feedback indicating it has:

Manifest is not changed for (SharedLambdaLayer), running incremental build                                                                                                                                                                                
Building layer 'SharedLambdaLayer'                                                                                                                                                                                                                        
 Running NodejsNpmBuilder:NpmPack                                                                                                                                                                                                                         
 Running NodejsNpmBuilder:CopyNpmrcAndLockfile                                                                                                                                                                                                            
 Running NodejsNpmBuilder:CopySource                                                                                                                                                                                                                      
 Running NodejsNpmBuilder:CopySource                                                                                                                                                                                                                      
 Running NodejsNpmBuilder:CleanUpNpmrc                                                                                                                                                                                                                    
Finished syncing Layer SharedLambdaLayer.                                                                                                                                                                                                                 
Syncing Function Layer Reference Sync HelloWorldFunction...                                                                                                                                                                                               
Finished syncing Function Layer Reference Sync HelloWorldFunction.      

SAM template:

  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs18.x
      Architectures:
        - x86_64
      Layers:
        - !Ref SharedLambdaLayer
      ....

  SharedLambdaLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      LayerName: shared-layer
      Description: Layer containing shared code
      ContentUri: shared/lib/
      RetentionPolicy: Delete
      CompatibleRuntimes:
        - nodejs18.x
    Metadata:
      BuildMethod: nodejs18.x

Steps to reproduce

(If you don't want to set it up from scratch, you can clone this repo, where I've done the below steps)

  1. sam initwith a typescript hello world example.
  2. Add a lambda layer in typescript, that exports a function that logs something or manipulates the return of the lambda
  3. npm install inside the hello-world function diretory to install esbuild
  4. sam build --build-in-source && sam deploy in the root
  5. sam sync --code --watch --build-in-source in the root.
  6. Update the hello-world and verify changes are live by curling the endpoint
  7. Update the layer (and observe the CLI feedback says that the referenced function has been updated, after updating the layer)
  8. curl the endpoint and observe that the changes have not been propagated sucessfully.

If we now make an update to the lambda function, the correct and latest layer code is used.

Observed result

Updating the Lambda layer, SAM cli syncs the layer and reports that the sync was sucessfull. Inspecting the Lambda function in the console, I also see that the layer version has been bumped. Invoking the lambda function, however, is using the old layer code.

Expected result

The latest layer code to be used.

Additional environment details

  1. OS: OSX
    1. If using the SAM CLI, sam --version: 1.108.0
  2. AWS region: eu-west-1, eu-north-1
@niklas-palm niklas-palm added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Aug 6, 2024
Copy link
Contributor

github-actions bot commented Aug 6, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

1 participant