-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathzip.sh
More file actions
executable file
·103 lines (84 loc) · 3.28 KB
/
Copy pathzip.sh
File metadata and controls
executable file
·103 lines (84 loc) · 3.28 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash -x
# Assuming the zip.sh script is run from inside the scripts folder
# clean up of old target directories
cd ..
TARGET_DIR=target
if [ -d "$TARGET_DIR" ]; then
echo "removing old ${TARGET_DIR}"
rm -r ${TARGET_DIR};
fi
# Add GO packages to GOPATH. Not needed if you are using Go modules
# export GOPATH=${HOME}/GO:${PATH}:$(pwd)
echo "Creating an binary executable using the go build command for Linux Systems."
binary_name="sumologic-extension"
ARCHITECTURES=(
amd64
arm64
)
for arch in "${ARCHITECTURES[@]}"; do
echo "Creating an binary executable for $arch"
extension_bin_dir="${TARGET_DIR}/${arch}/extensions"
extension_zip_dir="${TARGET_DIR}/${arch}/zip"
mkdir -p "${extension_bin_dir}"
mkdir -p "${extension_zip_dir}"
env GOOS="linux" GOARCH="$arch" go build -o "${extension_bin_dir}/${binary_name}" "lambda-extensions/${binary_name}.go"
status=$?
if [ $status -ne 0 ]; then
echo "Binary Generation Failed"
exit 1
fi
chmod +x "${extension_bin_dir}/${binary_name}"
echo "Creating the Zip file binary in extension folder."
cd "${TARGET_DIR}/${arch}"
zip -r "zip/${binary_name}.zip" "extensions/${binary_name}"
tar -czvf "zip/${binary_name}-${arch}.tar.gz" -C extensions "${binary_name}"
status=$?
if [ $status -ne 0 ]; then
echo "Zip Generation Failed"
exit 1
fi
cd -
echo "Create lambda Layer from the new ZIP file in the provided AWS_PROFILE aws account."
if [[ -z "${AWS_PROFILE}" ]]; then
export AWS_PROFILE="personal"
fi
AWS_REGIONS=(
us-east-1
us-east-2
eu-north-1
ap-south-1
eu-west-3
eu-west-2
eu-south-1
eu-west-1
ap-northeast-2
me-south-1
ap-northeast-1
sa-east-1
ca-central-1
ap-east-1
ap-southeast-1
ap-southeast-2
eu-central-1
eu-central-2
us-west-1
us-west-2
ca-west-1
)
echo "Using AWS_PROFILE: ${AWS_PROFILE}"
# We have layer name as sumologic-extension. Please change name for local testing.
layer_name="${binary_name}-${arch}"
for region in "${AWS_REGIONS[@]}"; do
layer_version=$(aws lambda publish-layer-version --layer-name ${layer_name} \
--description "The SumoLogic Extension collects lambda logs and send it to Sumo Logic." \
--license-info "Apache-2.0" --zip-file fileb://$(pwd)/${extension_zip_dir}/${binary_name}.zip \
--profile ${AWS_PROFILE} --region ${region} --output text --query Version )
# Dynamically get the partition for the region from AWS
caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${AWS_PROFILE} --query 'Arn' --output text)
partition=$(echo ${caller_arn} | cut -d':' -f2)
echo "Layer Arn: arn:${partition}:lambda:${region}:<accountId>:layer:${layer_name}:${layer_version} deployed to Region ${region}"
echo "Setting public permissions for layer version: ${layer_version}"
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}
# 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}
done
done