diff --git a/scripts/delete_old_layer_versions.sh b/scripts/delete_old_layer_versions.sh index b8893b4..1273340 100644 --- a/scripts/delete_old_layer_versions.sh +++ b/scripts/delete_old_layer_versions.sh @@ -39,6 +39,6 @@ for arch in "${ARCHITECTURES[@]}"; do for region in "${AWS_REGIONS[@]}"; do echo "Layer Arn: arn:aws:lambda:${region}::layer:${layer_name}:${layer_version} deleted from Region ${region}" - aws lambda delete-layer-version --layer-name ${layer_name} --version-number ${layer_version} --region ${region} + aws lambda delete-layer-version --layer-name ${layer_name} --version-number ${layer_version} --region ${region} --profile ${AWS_PROFILE} done -done +done \ No newline at end of file diff --git a/scripts/delete_old_layer_versions_special_partitions.sh b/scripts/delete_old_layer_versions_special_partitions.sh new file mode 100644 index 0000000..9c3b03b --- /dev/null +++ b/scripts/delete_old_layer_versions_special_partitions.sh @@ -0,0 +1,34 @@ +AWS_REGIONS=( + eusc-de-east-1 + ) + +# Set AWS_PROFILE_EUSC for European Sovereign Cloud regions (can be overridden via environment) +if [[ -z "${AWS_PROFILE_EUSC}" ]]; then + export AWS_PROFILE_EUSC="esc_personal" +fi + +echo "Using AWS_PROFILE_EUSC: ${AWS_PROFILE_EUSC}" + +binary_name="sumologic-extension" + +ARCHITECTURES=( + amd64 + arm64 +) +layer_version=1 +for arch in "${ARCHITECTURES[@]}"; do + + layer_name="${binary_name}-${arch}" + + for region in "${AWS_REGIONS[@]}"; do + + echo "Deleting from region ${region} using profile ${AWS_PROFILE_EUSC}" + + # Dynamically get the partition for the region from AWS + caller_arn=$(aws sts get-caller-identity --region ${region} --profile ${AWS_PROFILE_EUSC} --query 'Arn' --output text) + partition=$(echo ${caller_arn} | cut -d':' -f2) + + echo "Layer Arn: arn:${partition}:lambda:${region}::layer:${layer_name}:${layer_version} deleted from Region ${region}" + aws lambda delete-layer-version --layer-name ${layer_name} --version-number ${layer_version} --region ${region} --profile ${AWS_PROFILE_EUSC} + done +done \ No newline at end of file diff --git a/scripts/zip.sh b/scripts/zip.sh index 983d5f0..b15cb92 100755 --- a/scripts/zip.sh +++ b/scripts/zip.sh @@ -95,4 +95,4 @@ for arch in "${ARCHITECTURES[@]}"; do # 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 +done \ No newline at end of file diff --git a/scripts/zip_special_partitions.sh b/scripts/zip_special_partitions.sh new file mode 100644 index 0000000..4222cb9 --- /dev/null +++ b/scripts/zip_special_partitions.sh @@ -0,0 +1,88 @@ +#!/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." + # Set AWS_PROFILE_EUSC for European Sovereign Cloud regions (can be overridden via environment) + if [[ -z "${AWS_PROFILE_EUSC}" ]]; then + export AWS_PROFILE_EUSC="esc_personal" + fi + + AWS_REGIONS=( + eusc-de-east-1 + ) + + + echo "Using AWS_PROFILE_EUSC: ${AWS_PROFILE_EUSC}" + + # We have layer name as sumologic-extension. Please change name for local testing. + layer_name="${binary_name}-${arch}" + + for region in "${AWS_REGIONS[@]}"; do + + echo "Deploying to region ${region} using profile ${AWS_PROFILE_EUSC}" + + 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_EUSC} --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_EUSC} --query 'Arn' --output text) + partition=$(echo ${caller_arn} | cut -d':' -f2) + + echo "Layer Arn: arn:${partition}:lambda:${region}::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_EUSC} + # 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 \ No newline at end of file