Skip to content

Commit ffead19

Browse files
committed
add script mimicking lambda layer GHA locally
1 parent a487cbf commit ffead19

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

scripts/aws-deploy-local-layer.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Builds and deploys the Sentry AWS Lambda layer (including the Sentry SDK and the Sentry Lambda Extension)
4+
#
5+
# The currently checked out version of the SDK in your local directory is used.
6+
# The latest version of the Lambda Extension is fetched from the Sentry Release Registry.
7+
#
8+
# Note: While we normally try to write all of our scripts in TS, this is in bash because it's meant to exactly mirror
9+
# what the lambda-zipping GHA is doing (see https://github.com/getsentry/action-build-aws-lambda-extension)
10+
11+
set -euo pipefail
12+
13+
# Cleanup
14+
echo "Preparing local directories for new build..."
15+
rm -rf dist-serverless/
16+
rm -rf ./packages/serverless/build
17+
rm -rf ./packages/serverless/dist
18+
rm -rf ./packages/serverless/node_modules
19+
rm -f sentry-node-serverless-*.zip
20+
21+
# Creating Lambda layer
22+
echo "Creating Lambda layer in ./packages/serverless/build/aws/dist-serverless..."
23+
cd packages/serverless
24+
yarn build
25+
cd ../../
26+
echo "Done creating Lambda layer in ./packages/serverless/build/aws/dist-serverless."
27+
28+
# Move dist-serverless/ to the root folder for the action to pick it up.
29+
# This is only needed in this script, because in GitHub workflow
30+
# this is done with the upload-artifact/download-artifact actions
31+
echo "Copying Lambda layer in ./packages/serverless/build/aws/dist-serverless to working directory..."
32+
mv ./packages/serverless/build/aws/dist-serverless .
33+
echo "Done copying Lambda layer in ./packages/serverless/build/aws/dist-serverless to working directory."
34+
35+
# IMPORTANT:
36+
# Please make sure that this does the same as the GitHub action that
37+
# is building the Lambda layer in production!
38+
# see: https://github.com/getsentry/action-build-aws-lambda-extension/blob/main/action.yml#L23-L40
39+
40+
# Adding Sentry Lambda extension to Lambda layer
41+
echo "Adding Sentry Lambda extension to Lambda layer in ./dist-serverless..."
42+
mkdir -p dist-serverless/extensions
43+
curl -0 --silent --output dist-serverless/extensions/sentry-lambda-extension $(curl -s https://release-registry.services.sentry.io/apps/sentry-lambda-extension/latest | jq -r .files.\"sentry-lambda-extension\".url)
44+
chmod +x dist-serverless/extensions/sentry-lambda-extension
45+
echo "Done adding Sentry Lambda extension to Lambda layer in ./dist-serverless."
46+
47+
# Zip Lambda layer and included Lambda extension
48+
echo "Zipping Lambda layer and included Lambda extension..."
49+
cd dist-serverless/
50+
zip -r -y ../sentry-node-serverless-x.x.x-dev.zip .
51+
cd ..
52+
echo "Done Zipping Lambda layer and included Lambda extension to ./sentry-node-serverless-x.x.x-dev.zip."
53+
54+
# Deploying zipped Lambda layer to AWS
55+
echo "Deploying zipped Lambda layer to AWS..."
56+
57+
aws lambda publish-layer-version \
58+
--layer-name "SentryNodeServerlessSDK-local-dev" \
59+
--region "eu-central-1" \
60+
--zip-file "fileb://sentry-node-serverless-x.x.x-dev.zip" \
61+
--description "Local test build of SentryNodeServerlessSDK (can be deleted)" \
62+
--no-cli-pager
63+
64+
echo "Done deploying zipped Lambda layer to AWS as 'SentryNodeServerlessSDK-local-dev'."
65+
66+
echo "All done. Have a nice day!"

0 commit comments

Comments
 (0)