-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathlist_layers.sh
executable file
·81 lines (72 loc) · 2.36 KB
/
list_layers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019 Datadog, Inc.
# Lists most recent layers ARNs across regions to STDOUT
# Optionals args: [layer-name] [region]
set -e
LAYER_NAMES=(
"Datadog-Python38"
"Datadog-Python38-ARM"
"Datadog-Python39"
"Datadog-Python39-ARM"
"Datadog-Python310"
"Datadog-Python310-ARM"
"Datadog-Python311"
"Datadog-Python311-ARM"
"Datadog-Python312"
"Datadog-Python312-ARM"
"Datadog-Python313"
"Datadog-Python313-ARM"
)
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
LAYERS_MISSING_REGIONS=()
# Check region arg
if [ -z "$2" ]; then
>&2 echo "Region parameter not specified, running for all available regions."
REGIONS=$AVAILABLE_REGIONS
else
>&2 echo "Region parameter specified: $2"
if [[ ! "$AVAILABLE_REGIONS" == *"$2"* ]]; then
>&2 echo "Could not find $2 in available regions:" $AVAILABLE_REGIONS
>&2 echo ""
>&2 echo "EXITING SCRIPT."
exit 1
fi
REGIONS=($2)
fi
# Check region arg
if [ -z "$1" ]; then
>&2 echo "Layer parameter not specified, running for all layers "
LAYERS=("${LAYER_NAMES[@]}")
else
>&2 echo "Layer parameter specified: $1"
if [[ ! " ${LAYER_NAMES[@]} " =~ " ${1} " ]]; then
>&2 echo "Could not find $1 in layers: ${LAYER_NAMES[@]}"
>&2 echo ""
>&2 echo "EXITING SCRIPT."
return 1
fi
LAYERS=($1)
fi
for region in $REGIONS
do
for layer_name in "${LAYERS[@]}"
do
last_layer_arn=$(aws lambda list-layer-versions --layer-name $layer_name --region $region | jq -r ".LayerVersions | .[0] | .LayerVersionArn")
if [ "$last_layer_arn" == "null" ]; then
>&2 echo "No layer found for $region, $layer_name"
if [[ ! " ${LAYERS_MISSING_REGIONS[@]} " =~ " ${region} " ]]; then
LAYERS_MISSING_REGIONS+=( $region )
fi
else
echo $last_layer_arn
fi
done
done
if [ ${#LAYERS_MISSING_REGIONS[@]} -gt 0 ]; then
echo "WARNING: Following regions missing layers: ${LAYERS_MISSING_REGIONS[@]}"
echo "Please run ./add_new_region.sh <new_region> to add layers to the missing regions"
exit 1
fi