aws-sam-cli
aws-sam-cli copied to clipboard
`sam sync` with typescript not updating Lambda layer code in Lambda function
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)
-
sam init
with a typescript hello world example. - Add a lambda layer in typescript, that exports a function that logs something or manipulates the return of the lambda
-
npm install
inside the hello-world function diretory to install esbuild -
sam build --build-in-source && sam deploy
in the root -
sam sync --code --watch --build-in-source
in the root. - Update the hello-world and verify changes are live by curling the endpoint
- Update the layer (and observe the CLI feedback says that the referenced function has been updated, after updating the layer)
- 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
- OS: OSX
-
- If using the SAM CLI,
sam --version
: 1.108.0
- If using the SAM CLI,
- AWS region: eu-west-1, eu-north-1