Skip to content

Commit e0209db

Browse files
authored
Remove relay extension from AWS Layer (#2068)
we're reverting back to the older setup since the whole 'relay as AWS extension' experiment didn't really work out. * revert port override in DSN * remove gh action that bundles relay * zip in place as part of `make build_aws_lambda_layer` part of getsentry/team-webplatform-meta#58
1 parent 8a2b74f commit e0209db

File tree

6 files changed

+33
-67
lines changed

6 files changed

+33
-67
lines changed

.github/workflows/ci.yml

-12
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ jobs:
6868
pip install virtualenv
6969
# This will also trigger "make dist" that creates the Python packages
7070
make aws-lambda-layer
71-
72-
echo "Saving SDK_VERSION for later"
73-
export SDK_VERSION=$(grep "VERSION = " sentry_sdk/consts.py | cut -f3 -d' ' | tr -d '"')
74-
echo "SDK_VERSION=$SDK_VERSION"
75-
echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV
76-
- name: Upload Python AWS Lambda Layer
77-
uses: getsentry/action-build-aws-lambda-extension@v1
78-
with:
79-
artifact_name: ${{ github.sha }}
80-
zip_file_name: sentry-python-serverless-${{ env.SDK_VERSION }}.zip
81-
build_cache_paths: ${{ env.CACHED_BUILD_PATHS }}
82-
build_cache_key: ${{ env.BUILD_CACHE_KEY }}
8371
- name: Upload Python Packages
8472
uses: actions/upload-artifact@v3
8573
with:

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ help:
2020

2121
dist: .venv
2222
rm -rf dist dist-serverless build
23+
$(VENV_PATH)/bin/pip install wheel
2324
$(VENV_PATH)/bin/python setup.py sdist bdist_wheel
2425
.PHONY: dist
2526

scripts/aws-delete-lamba-layer-versions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -euo pipefail
88
# override default AWS region
99
export AWS_REGION=eu-central-1
1010

11-
LAYER_NAME=SentryPythonServerlessSDKLocalDev
11+
LAYER_NAME=SentryPythonServerlessSDK-local-dev
1212
VERSION="0"
1313

1414
while [[ $VERSION != "1" ]]

scripts/aws-deploy-local-layer.sh

+6-41
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,20 @@
99
set -euo pipefail
1010

1111
# Creating Lambda layer
12-
echo "Creating Lambda layer in ./dist-serverless ..."
12+
echo "Creating Lambda layer in ./dist ..."
1313
make aws-lambda-layer
14-
echo "Done creating Lambda layer in ./dist-serverless."
15-
16-
# IMPORTANT:
17-
# Please make sure that this part does the same as the GitHub action that
18-
# is building the Lambda layer in production!
19-
# see: https://github.com/getsentry/action-build-aws-lambda-extension/blob/main/action.yml#L23-L40
20-
21-
echo "Downloading relay..."
22-
mkdir -p dist-serverless/relay
23-
curl -0 --silent \
24-
--output dist-serverless/relay/relay \
25-
"$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)"
26-
chmod +x dist-serverless/relay/relay
27-
echo "Done downloading relay."
28-
29-
echo "Creating start script..."
30-
mkdir -p dist-serverless/extensions
31-
cat > dist-serverless/extensions/sentry-lambda-extension << EOT
32-
#!/bin/bash
33-
set -euo pipefail
34-
exec /opt/relay/relay run \
35-
--mode=proxy \
36-
--shutdown-timeout=2 \
37-
--upstream-dsn="\$SENTRY_DSN" \
38-
--aws-runtime-api="\$AWS_LAMBDA_RUNTIME_API"
39-
EOT
40-
chmod +x dist-serverless/extensions/sentry-lambda-extension
41-
echo "Done creating start script."
42-
43-
# Zip Lambda layer and included Lambda extension
44-
echo "Zipping Lambda layer and included Lambda extension..."
45-
cd dist-serverless/
46-
zip -r ../sentry-python-serverless-x.x.x-dev.zip \
47-
. \
48-
--exclude \*__pycache__\* --exclude \*.yml
49-
cd ..
50-
echo "Done Zipping Lambda layer and included Lambda extension to ./sentry-python-serverless-x.x.x-dev.zip."
51-
14+
echo "Done creating Lambda layer in ./dist"
5215

5316
# Deploying zipped Lambda layer to AWS
54-
echo "Deploying zipped Lambda layer to AWS..."
17+
ZIP=$(ls dist | grep serverless | head -n 1)
18+
echo "Deploying zipped Lambda layer $ZIP to AWS..."
5519

5620
aws lambda publish-layer-version \
5721
--layer-name "SentryPythonServerlessSDK-local-dev" \
5822
--region "eu-central-1" \
59-
--zip-file "fileb://sentry-python-serverless-x.x.x-dev.zip" \
23+
--zip-file "fileb://dist/$ZIP" \
6024
--description "Local test build of SentryPythonServerlessSDK (can be deleted)" \
25+
--compatible-runtimes python3.6 python3.7 python3.8 python3.9
6126
--no-cli-pager
6227

6328
echo "Done deploying zipped Lambda layer to AWS as 'SentryPythonServerlessSDK-local-dev'."

scripts/build_aws_lambda_layer.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(
1717
# type: (...) -> None
1818
self.base_dir = base_dir
1919
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)
20+
self.out_zip_filename = f"sentry-python-serverless-{SDK_VERSION}.zip"
2021

2122
def make_directories(self):
2223
# type: (...) -> None
@@ -57,16 +58,35 @@ def create_init_serverless_sdk_package(self):
5758
"scripts/init_serverless_sdk.py", f"{serverless_sdk_path}/__init__.py"
5859
)
5960

61+
def zip(self):
62+
# type: (...) -> None
63+
subprocess.run(
64+
[
65+
"zip",
66+
"-q", # Quiet
67+
"-x", # Exclude files
68+
"**/__pycache__/*", # Files to be excluded
69+
"-r", # Recurse paths
70+
self.out_zip_filename, # Output filename
71+
PYTHON_SITE_PACKAGES, # Files to be zipped
72+
],
73+
cwd=self.base_dir,
74+
check=True, # Raises CalledProcessError if exit status is non-zero
75+
)
6076

61-
def build_layer_dir():
77+
shutil.copy(
78+
os.path.join(self.base_dir, self.out_zip_filename),
79+
os.path.abspath(DIST_PATH)
80+
)
81+
82+
def build_packaged_zip():
6283
with tempfile.TemporaryDirectory() as base_dir:
6384
layer_builder = LayerBuilder(base_dir)
6485
layer_builder.make_directories()
6586
layer_builder.install_python_packages()
6687
layer_builder.create_init_serverless_sdk_package()
67-
68-
shutil.copytree(base_dir, "dist-serverless")
88+
layer_builder.zip()
6989

7090

7191
if __name__ == "__main__":
72-
build_layer_dir()
92+
build_packaged_zip()

scripts/init_serverless_sdk.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@
1818
from typing import Any
1919

2020

21-
def extension_relay_dsn(original_dsn):
22-
dsn = Dsn(original_dsn)
23-
dsn.host = "localhost"
24-
dsn.port = 5333
25-
dsn.scheme = "http"
26-
return str(dsn)
27-
28-
2921
# Configure Sentry SDK
3022
sentry_sdk.init(
31-
dsn=extension_relay_dsn(os.environ["SENTRY_DSN"]),
23+
dsn=os.environ["SENTRY_DSN"],
3224
integrations=[AwsLambdaIntegration(timeout_warning=True)],
3325
traces_sample_rate=float(os.environ["SENTRY_TRACES_SAMPLE_RATE"]),
3426
)

0 commit comments

Comments
 (0)