- Newest
- Most votes
- Most comments
The challenge you're facing is common when working with Lambda layers across multiple SAM applications. The sam watch command doesn't automatically update function configurations to use new layer versions, as you've correctly observed.
Here are some recommended approaches for your local development workflow:
Option 1: Separate Stack for Layers with Manual Updates
Continue with your current architecture but implement a workflow to update the function configurations:
- Run
sam watchfor your layers stack - When a layer changes, use AWS CLI to update your functions to use the new layer version:
aws lambda update-function-configuration \
--function-name your-function-name \
--layers arn:aws:lambda:region:account:layer:layer-name:new-version
You could automate this with a script that:
- Watches for layer deployments
- Retrieves the new layer ARN
- Updates the function configuration
Option 2: Include Layers in Function Stacks During Development
For local development only, you could temporarily include the layer code directly in your function stacks:
- Define the layer in both your layers stack (for production) and function stacks (for development)
- In the function stack, reference the local layer definition instead of using a parameter
- When ready for production, switch back to using the parameter-based approach
Option 3: Custom Resource in CloudFormation
Implement a custom resource in your function stack that checks for the latest layer version and updates the function configuration accordingly. This would allow your functions to automatically use the latest layer version.
Option 4: Use Parameters with Manual Triggers
Continue using parameters but manually trigger redeployments:
- Run
sam watchfor your layers stack - When a layer changes, manually run
sam deployfor your function stack with the updated layer ARN parameter
Important considerations:
- Keep your local development dependencies in sync with the Lambda Layer version
- Ensure your build process excludes packages from your deployment bundle that are provided by the layer
- Consider the trade-offs between development speed and maintaining production-like environments
While AWS SAM doesn't have a built-in feature to automatically update function configurations when layers change across stacks, these approaches can help you establish an efficient development workflow.
Sources
Is there a way to only update lambda layers? | AWS re:Post
Using AWS SAM with layers - AWS Lambda
Lambda layers - Powertools for AWS Lambda (TypeScript)
Relevant content
asked 2 years ago
asked 3 years ago
asked a year ago
- AWS OFFICIALUpdated 3 years ago
