Skip to content

Commit a4f9d98

Browse files
committed
Introducing handling for different aws profile - seperate for ESC in zip.sh deployment script
1 parent 934e0f2 commit a4f9d98

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

scripts/delete_old_layer_versions.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ AWS_REGIONS=(
1818
eu-central-1
1919
us-west-1
2020
us-west-2
21+
eusc-de-east-1
2122
)
2223

2324

2425
if [[ -z "${AWS_PROFILE}" ]]; then
2526
export AWS_PROFILE="personal"
2627
fi
28+
29+
# Set AWS_PROFILE_EUSC for European Sovereign Cloud regions (can be overridden via environment)
30+
if [[ -z "${AWS_PROFILE_EUSC}" ]]; then
31+
export AWS_PROFILE_EUSC="esc_personal"
32+
fi
33+
2734
echo "Using AWS_PROFILE: ${AWS_PROFILE}"
35+
echo "Using AWS_PROFILE_EUSC: ${AWS_PROFILE_EUSC}"
2836

2937
binary_name="sumologic-extension"
3038

@@ -38,11 +46,20 @@ for arch in "${ARCHITECTURES[@]}"; do
3846
layer_name="${binary_name}-${arch}"
3947

4048
for region in "${AWS_REGIONS[@]}"; do
49+
# Auto-detect profile based on region prefix
50+
if [[ "${region}" =~ ^eusc- ]]; then
51+
profile="${AWS_PROFILE_EUSC}"
52+
else
53+
profile="${AWS_PROFILE}"
54+
fi
55+
56+
echo "Deleting from region ${region} using profile ${profile}"
57+
4158
# Dynamically get the partition for the region from AWS
42-
caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${AWS_PROFILE} --query 'Arn' --output text)
59+
caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${profile} --query 'Arn' --output text)
4360
partition=$(echo ${caller_arn} | cut -d':' -f2)
4461

4562
echo "Layer Arn: arn:${partition}:lambda:${region}:<accountId>:layer:${layer_name}:${layer_version} deleted from Region ${region}"
46-
aws lambda delete-layer-version --layer-name ${layer_name} --version-number ${layer_version} --region ${region} --profile ${AWS_PROFILE}
63+
aws lambda delete-layer-version --layer-name ${layer_name} --version-number ${layer_version} --region ${region} --profile ${profile}
4764
done
4865
done

scripts/zip.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ for arch in "${ARCHITECTURES[@]}"; do
5454
export AWS_PROFILE="personal"
5555
fi
5656

57+
# Set AWS_PROFILE_EUSC for European Sovereign Cloud regions (can be overridden via environment)
58+
if [[ -z "${AWS_PROFILE_EUSC}" ]]; then
59+
export AWS_PROFILE_EUSC="esc_personal"
60+
fi
61+
5762
AWS_REGIONS=(
5863
us-east-1
5964
us-east-2
@@ -76,27 +81,38 @@ for arch in "${ARCHITECTURES[@]}"; do
7681
us-west-1
7782
us-west-2
7883
ca-west-1
84+
eusc-de-east-1
7985
)
8086

8187
echo "Using AWS_PROFILE: ${AWS_PROFILE}"
88+
echo "Using AWS_PROFILE_EUSC: ${AWS_PROFILE_EUSC}"
8289

8390
# We have layer name as sumologic-extension. Please change name for local testing.
8491
layer_name="${binary_name}-${arch}"
8592

8693
for region in "${AWS_REGIONS[@]}"; do
94+
# Auto-detect profile based on region prefix
95+
if [[ "${region}" =~ ^eusc- ]]; then
96+
profile="${AWS_PROFILE_EUSC}"
97+
else
98+
profile="${AWS_PROFILE}"
99+
fi
100+
101+
echo "Deploying to region ${region} using profile ${profile}"
102+
87103
layer_version=$(aws lambda publish-layer-version --layer-name ${layer_name} \
88104
--description "The SumoLogic Extension collects lambda logs and send it to Sumo Logic." \
89105
--license-info "Apache-2.0" --zip-file fileb://$(pwd)/${extension_zip_dir}/${binary_name}.zip \
90-
--profile ${AWS_PROFILE} --region ${region} --output text --query Version )
106+
--profile ${profile} --region ${region} --output text --query Version )
91107

92108
# Dynamically get the partition for the region from AWS
93-
caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${AWS_PROFILE} --query 'Arn' --output text)
109+
caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${profile} --query 'Arn' --output text)
94110
partition=$(echo ${caller_arn} | cut -d':' -f2)
95111

96112
echo "Layer Arn: arn:${partition}:lambda:${region}:<accountId>:layer:${layer_name}:${layer_version} deployed to Region ${region}"
97113

98114
echo "Setting public permissions for layer version: ${layer_version}"
99-
aws lambda add-layer-version-permission --layer-name ${layer_name} --statement-id ${layer_name}-prod --version-number $layer_version --principal '*' --action lambda:GetLayerVersion --region ${region} --profile ${AWS_PROFILE}
115+
aws lambda add-layer-version-permission --layer-name ${layer_name} --statement-id ${layer_name}-prod --version-number $layer_version --principal '*' --action lambda:GetLayerVersion --region ${region} --profile ${profile}
100116
# aws lambda add-layer-version-permission --layer-name ${layer_name} --statement-id ${layer_name}-dev --version-number ${layer_version} --principal '956882708938' --action lambda:GetLayerVersion --region ${region}
101117
done
102118

0 commit comments

Comments
 (0)