-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathaws-deploy-local-layer.sh
executable file
·90 lines (78 loc) · 3.63 KB
/
aws-deploy-local-layer.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
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
#
# Builds and deploys the Sentry AWS Lambda layer (including the Sentry SDK and the Sentry Lambda Extension)
#
# The currently checked out version of the SDK in your local directory is used.
# The latest version of the Lambda Extension is fetched from the Sentry Release Registry.
#
# Note: While we normally try to write all of our scripts in TS, this is in bash because it's meant to exactly mirror
# what the lambda-zipping GHA is doing (see https://github.com/getsentry/action-build-aws-lambda-extension)
set -euo pipefail
# Remove old distribution directories and zip files.
echo "Preparing local directories for new build..."
rm -rf dist-serverless/
rm -rf ./packages/serverless/build
rm -rf ./packages/serverless/dist
rm -rf ./packages/serverless/node_modules
rm -f sentry-node-serverless-*.zip
# Creating Lambda layer
echo "Creating Lambda layer in ./packages/serverless/build/aws/dist-serverless..."
cd packages/serverless
yarn build
cd ../../
echo "Done creating Lambda layer in ./packages/serverless/build/aws/dist-serverless."
# Move dist-serverless/ to the root folder for the action to pick it up.
# This is only needed in this script, because in GitHub workflow
# this is done with the upload-artifact/download-artifact actions
echo "Copying Lambda layer in ./packages/serverless/build/aws/dist-serverless to working directory..."
mv ./packages/serverless/build/aws/dist-serverless .
echo "Done copying Lambda layer in ./packages/serverless/build/aws/dist-serverless to working directory."
# IMPORTANT:
# Please make sure that this does the same as the GitHub action that
# is building the Lambda layer in production!
# see: https://github.com/getsentry/action-build-aws-lambda-extension/blob/main/action.yml#L23-L40
echo "Downloading relay..."
# Make directory (if not existing)
mkdir -p dist-serverless/relay
# Download releay from release registry to dist-serverless/relay/relay
curl -0 --silent \
--output dist-serverless/relay/relay \
"$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)"
# Make file executable
chmod +x dist-serverless/relay/relay
echo "Done downloading relay."
echo "Creating start script..."
# Make directory (if not existing)
mkdir -p dist-serverless/extensions
# Create 'sentry-lambda-extension' script that starts relay.
# The file has to have exactly this name, because the executable files of
# Lambda extensions need to have same file name as the name that they use
# to register with AWS Lambda environment
cat > dist-serverless/extensions/sentry-lambda-extension << EOT
#!/bin/bash
set -euo pipefail
exec /opt/relay/relay run \
--mode=proxy \
--shutdown-timeout=2 \
--upstream-dsn="\$SENTRY_DSN" \
--aws-runtime-api="\$AWS_LAMBDA_RUNTIME_API"
EOT
# Make script executable
chmod +x dist-serverless/extensions/sentry-lambda-extension
echo "Done creating start script."
# Zip Lambda layer and included Lambda extension
echo "Zipping Lambda layer and included Lambda extension..."
cd dist-serverless/
zip -r -y ../sentry-node-serverless-x.x.x-dev.zip .
cd ..
echo "Done Zipping Lambda layer and included Lambda extension to ./sentry-node-serverless-x.x.x-dev.zip."
# Deploying zipped Lambda layer to AWS
echo "Deploying zipped Lambda layer to AWS..."
aws lambda publish-layer-version \
--layer-name "SentryNodeServerlessSDK-local-dev" \
--region "eu-central-1" \
--zip-file "fileb://sentry-node-serverless-x.x.x-dev.zip" \
--description "Local test build of SentryNodeServerlessSDK (can be deleted)" \
--no-cli-pager
echo "Done deploying zipped Lambda layer to AWS as 'SentryNodeServerlessSDK-local-dev'."
echo "All done. Have a nice day!"