Is there a way to only update lambda layers?

0

Im looking a way to prepare my python lambda layers, zip them up, and deploy them to a specific corresponding lamba layers for a specific cloudformation stack instance.

Ideally I could do this using aws cli or sam cli (e.g. sam sync) but I cant find a way to do this without deploying the full stack which includes the lambda functions.

2 Answers
0

Yes, there are ways to update Lambda layers without deploying the full stack, although it's not directly supported through AWS SAM or CloudFormation without some additional steps.

Here are a few approaches you can consider:

  1. Use the AWS Lambda Console: You can manually update the layer version for specific functions using the Lambda console. Navigate to the Layers page, select the layer you want to update, choose the functions you want to modify, and update them to use the new layer version.

  2. AWS CLI: You can use the AWS CLI to publish a new layer version and then update the functions to use this new version. This would involve using the publish-layer-version command to create a new layer version, followed by update-function-configuration to update the functions to use the new layer.

  3. Custom Resource in CloudFormation: You could implement a custom resource in your CloudFormation template that checks for content changes in your layer and triggers updates accordingly. This would allow you to update just the layer without redeploying the entire stack.

  4. Separate Stack for Layers: Consider creating a separate CloudFormation stack just for your layers. This way, you can update and deploy only the layer stack without touching the main application stack.

  5. Use Parameters: In your CloudFormation template, use a parameter to represent the layer version. When you need to update the layer, you can update this parameter value, which will trigger an update of the layer without necessarily redeploying the entire stack.

While these methods provide ways to update layers more selectively, it's important to note that AWS SAM and CloudFormation are designed to manage the entire application stack as a unit. For more granular control over individual components like layers, you might need to combine these tools with custom scripts or workflows.
Sources
Adding layers to functions - AWS Lambda
Lambda Layer not changing when taken from S3 in cf template | AWS re:Post

profile picture
answered 7 days ago
profile pictureAWS
EXPERT
reviewed 6 days ago
0

Yes, create new Lambda layer

aws lambda publish-layer-version \
    --layer-name new-layer \
    --description "New Lambda Layer" \
    --zip-file fileb://layer.zip \
    --compatible-runtimes python3.10 python3.11

This will give you the lambda layer ARN. Then update the lambda function

aws lambda update-function-configuration \
    --function-name my-demo-function \
    --layers arn:aws:lambda:ap-southeast-2:123456123456:layer:new-layer:4  ## obtained from previous section
answered 6 days ago
profile pictureAWS
EXPERT
reviewed 6 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions