Skip to content

Instantly share code, notes, and snippets.

@elviswolcott
Created January 26, 2020 08:05
Show Gist options
  • Save elviswolcott/01b9c1115195060e6722a03b7804b6ff to your computer and use it in GitHub Desktop.
Save elviswolcott/01b9c1115195060e6722a03b7804b6ff to your computer and use it in GitHub Desktop.
Delete all Lambda layer versions across all regions
layer=$1
get_regions () {
echo $(aws ssm get-parameters-by-path --region "us-east-1" --path /aws/service/global-infrastructure/services/lambda/regions --query 'Parameters[].Value' --output text | tr '[:blank:]' '\n' | grep -v -e ^cn- -e ^us-gov- | sort -r)
}
regions=$(get_regions)
get_versions () {
echo $(aws lambda list-layer-versions --layer-name "$layer" --region "$region" --output text --query LayerVersions[].Version | tr '[:blank:]' '\n')
}
for region in $regions;
do
versions=$(get_versions "$region")
for version in $versions;
do
echo "deleting arn:aws:lambda:$region:*:layer:$layer:$version"
aws lambda delete-layer-version --region "$region" --layer-name "$layer" --version "$version" > /dev/null
done
done
@hacksonX
Copy link

Instead of --version
The flag should be
--version-number
For both cli-v1 and cli-v2

@gene1wood
Copy link

@hacksonX is correct the argument is --version-number not --version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment