1+ #! /bin/bash -x
2+ # Assuming the zip.sh script is run from inside the scripts folder
3+
4+ # clean up of old target directories
5+ cd ..
6+ TARGET_DIR=target
7+ if [ -d " $TARGET_DIR " ]; then
8+ echo " removing old ${TARGET_DIR} "
9+ rm -r ${TARGET_DIR} ;
10+ fi
11+
12+ # Add GO packages to GOPATH. Not needed if you are using Go modules
13+ # export GOPATH=${HOME}/GO:${PATH}:$(pwd)
14+
15+ echo " Creating an binary executable using the go build command for Linux Systems."
16+ binary_name=" sumologic-extension"
17+
18+
19+ ARCHITECTURES=(
20+ amd64
21+ arm64
22+ )
23+
24+ for arch in " ${ARCHITECTURES[@]} " ; do
25+
26+ echo " Creating an binary executable for $arch "
27+ extension_bin_dir=" ${TARGET_DIR} /${arch} /extensions"
28+ extension_zip_dir=" ${TARGET_DIR} /${arch} /zip"
29+ mkdir -p " ${extension_bin_dir} "
30+ mkdir -p " ${extension_zip_dir} "
31+
32+ env GOOS=" linux" GOARCH=" $arch " go build -o " ${extension_bin_dir} /${binary_name} " " lambda-extensions/${binary_name} .go"
33+
34+ status=$?
35+ if [ $status -ne 0 ]; then
36+ echo " Binary Generation Failed"
37+ exit 1
38+ fi
39+ chmod +x " ${extension_bin_dir} /${binary_name} "
40+
41+ echo " Creating the Zip file binary in extension folder."
42+ cd " ${TARGET_DIR} /${arch} "
43+ zip -r " zip/${binary_name} .zip" " extensions/${binary_name} "
44+ tar -czvf " zip/${binary_name} -${arch} .tar.gz" -C extensions " ${binary_name} "
45+ status=$?
46+ if [ $status -ne 0 ]; then
47+ echo " Zip Generation Failed"
48+ exit 1
49+ fi
50+ cd -
51+
52+ echo " Create lambda Layer from the new ZIP file in the provided AWS_PROFILE aws account."
53+ # Set AWS_PROFILE_EUSC for European Sovereign Cloud regions (can be overridden via environment)
54+ if [[ -z " ${AWS_PROFILE_EUSC} " ]]; then
55+ export AWS_PROFILE_EUSC=" esc_personal"
56+ fi
57+
58+ AWS_REGIONS=(
59+ eusc-de-east-1
60+ )
61+
62+
63+ echo " Using AWS_PROFILE_EUSC: ${AWS_PROFILE_EUSC} "
64+
65+ # We have layer name as sumologic-extension. Please change name for local testing.
66+ layer_name=" ${binary_name} -${arch} "
67+
68+ for region in " ${AWS_REGIONS[@]} " ; do
69+
70+ echo " Deploying to region ${region} using profile ${AWS_PROFILE_EUSC} "
71+
72+ layer_version=$( aws lambda publish-layer-version --layer-name ${layer_name} \
73+ --description " The SumoLogic Extension collects lambda logs and send it to Sumo Logic." \
74+ --license-info " Apache-2.0" --zip-file fileb://$( pwd) /${extension_zip_dir} /${binary_name} .zip \
75+ --profile ${AWS_PROFILE_EUSC} --region ${region} --output text --query Version )
76+
77+ # Dynamically get the partition for the region from AWS
78+ caller_arn=$( aws sts get-caller-identity --region ${region} --profile ${AWS_PROFILE_EUSC} --query ' Arn' --output text)
79+ partition=$( echo ${caller_arn} | cut -d' :' -f2)
80+
81+ echo " Layer Arn: arn:${partition} :lambda:${region} :<accountId>:layer:${layer_name} :${layer_version} deployed to Region ${region} "
82+
83+ echo " Setting public permissions for layer version: ${layer_version} "
84+ 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_EUSC}
85+ # 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}
86+ done
87+
88+ done
0 commit comments