#!/bin/sh REGION=`aws configure get region` # Fetch all distinct Lambda layers aws lambda list-layers --region $REGION | tee lambda_layers.json | jq -r '.Layers[].LayerArn' | sort -u | # Loop through each layer ARN and download the latest version while read -r LAYER_ARN; do # Get the latest version ARN VERSION_ARN=$(aws lambda list-layer-versions --layer-name $LAYER_ARN --region $REGION --max-items 1 | jq -r '.LayerVersions[0].LayerVersionArn') # Get the download URL for the latest version S3_URL=$(aws lambda get-layer-version-by-arn --arn $VERSION_ARN --region $REGION | jq -r '.Content.Location') # Download and save with a meaningful name LAYER_NAME=$(echo $LAYER_ARN | awk -F':' '{print $7}') wget -O "$LAYER_NAME.zip" "$S3_URL" unzip -d "$LAYER_NAME" "$LAYER_NAME.zip" done