-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Build new Lambda extension (#1383) * Use new GitHub action for creating Lambda layer zip. * Use new GitHub action for creating zip. * Replace original DSN host/port with localhost:3000 (#1414) * Added script for locally building/release Lambda layer * Added script to attach layer to function Co-authored-by: Neel Shah <neel.shah@sentry.io>
- Loading branch information
1 parent
3d38329
commit 0352c79
Showing
11 changed files
with
295 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ pip-log.txt | |
/build | ||
/dist | ||
/dist-serverless | ||
sentry-python-serverless*.zip | ||
.cache | ||
.idea | ||
.eggs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Contributing to Sentry AWS Lambda Layer | ||
|
||
All the general terms of the [CONTRIBUTING.md](CONTRIBUTING.md) apply. | ||
|
||
## Development environment | ||
|
||
You need to have a AWS account and AWS CLI installed and setup. | ||
|
||
We put together two helper functions that can help you with development: | ||
|
||
- `./scripts/aws-deploy-local-layer.sh` | ||
|
||
This script [scripts/aws-deploy-local-layer.sh](scripts/aws-deploy-local-layer.sh) will take the code you have checked out locally, create a Lambda layer out of it and deploy it to the `eu-central-1` region of your configured AWS account using `aws` CLI. | ||
|
||
The Lambda layer will have the name `SentryPythonServerlessSDK-local-dev` | ||
|
||
- `./scripts/aws-attach-layer-to-lambda-function.sh` | ||
|
||
You can use this script [scripts/aws-attach-layer-to-lambda-function.sh](scripts/aws-attach-layer-to-lambda-function.sh) to attach the Lambda layer you just deployed (using the first script) onto one of your existing Lambda functions. You will have to give the name of the Lambda function to attach onto as an argument. (See the script for details.) | ||
|
||
With this two helper scripts it should be easy to rapidly iterate your development on the Lambda layer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Attaches the layer `SentryPythonServerlessSDK-local-dev` to a given lambda function. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
# Check for argument | ||
if [ $# -eq 0 ] | ||
then | ||
SCRIPT_NAME=$(basename "$0") | ||
echo "ERROR: No argument supplied. Please give the name of a Lambda function!" | ||
echo "" | ||
echo "Usage: $SCRIPT_NAME <lambda-function-name>" | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
FUNCTION_NAME=$1 | ||
|
||
echo "Getting ARN of newest Sentry lambda layer..." | ||
LAYER_ARN=$(aws lambda list-layer-versions --layer-name SentryPythonServerlessSDK-local-dev --query "LayerVersions[0].LayerVersionArn" | tr -d '"') | ||
echo "Done getting ARN of newest Sentry lambda layer $LAYER_ARN." | ||
|
||
echo "Attaching Lamba layer to function $FUNCTION_NAME..." | ||
echo "Warning: This remove all other layers!" | ||
aws lambda update-function-configuration \ | ||
--function-name "$FUNCTION_NAME" \ | ||
--layers "$LAYER_ARN" \ | ||
--no-cli-pager | ||
echo "Done attaching Lamba layer to function '$FUNCTION_NAME'." | ||
|
||
echo "All done. Have a nice day!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Deletes all versions of the layer specified in LAYER_NAME in one region. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
# override default AWS region | ||
export AWS_REGION=eu-central-1 | ||
|
||
LAYER_NAME=SentryPythonServerlessSDKLocalDev | ||
VERSION="0" | ||
|
||
while [[ $VERSION != "1" ]] | ||
do | ||
VERSION=$(aws lambda list-layer-versions --layer-name $LAYER_NAME | jq '.LayerVersions[0].Version') | ||
aws lambda delete-layer-version --layer-name $LAYER_NAME --version-number $VERSION | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/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. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
# Creating Lambda layer | ||
echo "Creating Lambda layer in ./dist-serverless ..." | ||
make aws-lambda-layer | ||
echo "Done creating Lambda layer in ./dist-serverless." | ||
|
||
# IMPORTANT: | ||
# Please make sure that this part 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..." | ||
mkdir -p dist-serverless/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)" | ||
chmod +x dist-serverless/relay/relay | ||
echo "Done downloading relay." | ||
|
||
echo "Creating start script..." | ||
mkdir -p dist-serverless/extensions | ||
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 | ||
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 ../sentry-python-serverless-x.x.x-dev.zip \ | ||
. \ | ||
--exclude \*__pycache__\* --exclude \*.yml | ||
cd .. | ||
echo "Done Zipping Lambda layer and included Lambda extension to ./sentry-python-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 "SentryPythonServerlessSDK-local-dev" \ | ||
--region "eu-central-1" \ | ||
--zip-file "fileb://sentry-python-serverless-x.x.x-dev.zip" \ | ||
--description "Local test build of SentryPythonServerlessSDK (can be deleted)" \ | ||
--no-cli-pager | ||
|
||
echo "Done deploying zipped Lambda layer to AWS as 'SentryPythonServerlessSDK-local-dev'." | ||
|
||
echo "All done. Have a nice day!" |
Oops, something went wrong.