1

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Homebrew installed jq and used it. Very handy. Also opened my eyes to possibilities of using multiple commands in line with, for example, | python3 "<code>" and that, plus this, have taken me further. Thank you very much!
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.