eccadena
eccadena

Reputation: 171

Dynamically change version number of Lambda Layer using a shell executable

I am using a shell script that calls for some custom packages to be zipped and layered on lambda.

After deploying the layer via aws lambda publish-layer-version the layer version, obviously, goes up. The next command in my .sh script is something like

aws lambda update-function-configuration --function-name myfunc --layers arn:aws:lambda:<region>:273846758499:layer:<layer_name>:<version>

Since I am new to scripting in general I am open to any workable solutions but I am looking to iterate the <version> to the most recent version available on Lambda. How can this be written in this language?

Upvotes: 1

Views: 1276

Answers (2)

Krupesh Patel
Krupesh Patel

Reputation: 51

When you use publish-layer-version, it always creates a unique ARN for every lambda function.

I was stuck in the same situation when I created the continuous deployment/delivery pipeline. When the user pushes to the main branch, then the code directly deploys into the lambda function and creates or updates the lambda layer. But I am confused about how to connect the lambda function to the lambda layers.

That time, I had to do something like this.

layer=$(aws lambda list-layers --query "Layers[0].LayerArn")

 aws lambda update-function-configuration --function-name $lambda_function_name --layers $layer

Upvotes: 1

saart
saart

Reputation: 402

You can simply parse the response from the first command:

For example, I'm using here jq, which parses jsons in bash.

version=$(aws lambda publish-layer-version --layer-name <your name> --zip-file <zip> --region "us-east-1" | jq -r '.LayerVersionArn')

Then, you can upload with: aws lambda update-function-configuration --function-name <name> --layers $version

Disclosure: I work for Lumigo, a company that provides serverless monitoring.

Upvotes: 3

Related Questions