Skip to content

Commit 85a6e60

Browse files
committed
Remove relay extension from AWS Layer
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 `buildLambdaLayer` part of getsentry/team-webplatform-meta#58
1 parent 0eb81bc commit 85a6e60

File tree

7 files changed

+33
-130
lines changed

7 files changed

+33
-130
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -253,43 +253,6 @@ jobs:
253253
# `job_build` can't see `job_install_deps` and what it returned)
254254
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
255255

256-
job_pack_aws_lambda_layer:
257-
name: Pack and Upload AWS Lambda Layer
258-
needs: [job_get_metadata, job_build]
259-
# only upload the zipped layer file if we're about to release
260-
if: startsWith(github.ref, 'refs/heads/release/')
261-
runs-on: ubuntu-20.04
262-
steps:
263-
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
264-
uses: actions/checkout@v3
265-
with:
266-
ref: ${{ env.HEAD_COMMIT }}
267-
- name: Set up Node
268-
uses: actions/setup-node@v3
269-
with:
270-
node-version-file: 'package.json'
271-
- name: Restore caches
272-
uses: ./.github/actions/restore-cache
273-
env:
274-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
275-
276-
- name: Get SDK version
277-
# `jq` reads JSON files, and `tee` pipes its input to the given location and to stdout. (Adding `-a` is the
278-
# equivalent of using >> rather than >.)
279-
run: |
280-
export SDK_VERSION=$(cat packages/core/package.json | jq --raw-output '.version')
281-
echo "SDK_VERSION=$SDK_VERSION" | tee -a $GITHUB_ENV
282-
- name: Move dist-serverless to root directory (requirement for zipping action)
283-
run: |
284-
mv ./packages/serverless/build/aws/dist-serverless .
285-
- name: Create and upload final zip file
286-
uses: getsentry/action-build-aws-lambda-extension@v1
287-
with:
288-
artifact_name: ${{ env.HEAD_COMMIT }}
289-
zip_file_name: sentry-node-serverless-${{ env.SDK_VERSION }}.zip
290-
build_cache_paths: ${{ env.CACHED_BUILD_PATHS }}
291-
build_cache_key: ${{ env.BUILD_CACHE_KEY }}
292-
293256
job_size_check:
294257
name: Size Check
295258
needs: [job_get_metadata, job_build]
@@ -399,6 +362,7 @@ jobs:
399362
${{ github.workspace }}/packages/integrations/build/bundles/**
400363
${{ github.workspace }}/packages/replay/build/bundles/**
401364
${{ github.workspace }}/packages/**/*.tgz
365+
${{ github.workspace }}/packages/serverless/build/aws/dist-serverless/*.zip
402366
403367
job_browser_unit_tests:
404368
name: Browser Unit Tests

packages/serverless/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"find-up": "^5.0.0",
3535
"google-gax": "^2.9.0",
3636
"nock": "^13.0.4",
37-
"npm-packlist": "^2.1.4",
38-
"read-pkg": "^5.2.0"
37+
"npm-packlist": "^2.1.4"
3938
},
4039
"scripts": {
4140
"build": "run-p build:transpile build:types build:bundle",

packages/serverless/scripts/buildLambdaLayer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from 'fs';
44
import * as rimraf from 'rimraf';
55

66
import { ensureBundleBuildPrereqs } from '../../../scripts/ensure-bundle-deps';
7+
import { version } from '../package.json';
78

89
/**
910
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
@@ -46,6 +47,11 @@ async function buildLambdaLayer(): Promise<void> {
4647
'../build/npm/cjs/awslambda-auto.js',
4748
'build/aws/dist-serverless/nodejs/node_modules/@sentry/serverless/dist/awslambda-auto.js',
4849
);
50+
51+
const zipFilename = `sentry-node-serverless-${version}.zip`;
52+
console.log(`Creating final layer zip file ${zipFilename}.`);
53+
// need to preserve the symlink above with -y
54+
run(`zip -r -y ${zipFilename} .`, { cwd: 'build/aws/dist-serverless' });
4955
}
5056

5157
void buildLambdaLayer();

packages/serverless/src/awslambda.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import type { Scope } from '@sentry/node';
33
import * as Sentry from '@sentry/node';
44
import { captureException, captureMessage, flush, getCurrentHub, withScope } from '@sentry/node';
55
import type { Integration } from '@sentry/types';
6-
import {
7-
baggageHeaderToDynamicSamplingContext,
8-
dsnFromString,
9-
dsnToString,
10-
extractTraceparentData,
11-
isString,
12-
logger,
13-
} from '@sentry/utils';
6+
import { baggageHeaderToDynamicSamplingContext, extractTraceparentData, isString, logger } from '@sentry/utils';
147
// NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil
158
// eslint-disable-next-line import/no-unresolved
169
import type { Context, Handler } from 'aws-lambda';
@@ -56,27 +49,6 @@ export interface WrapperOptions {
5649

5750
export const defaultIntegrations: Integration[] = [...Sentry.defaultIntegrations, new AWSServices({ optional: true })];
5851

59-
/**
60-
* Changes a Dsn to point to the `relay` server running in the Lambda Extension.
61-
*
62-
* This is only used by the serverless integration for AWS Lambda.
63-
*
64-
* @param originalDsn The original Dsn of the customer.
65-
* @returns Dsn pointing to Lambda extension.
66-
*/
67-
function extensionRelayDSN(originalDsn: string | undefined): string | undefined {
68-
if (originalDsn === undefined) {
69-
return undefined;
70-
}
71-
72-
const dsn = dsnFromString(originalDsn);
73-
dsn.host = 'localhost';
74-
dsn.port = '5333';
75-
dsn.protocol = 'http';
76-
77-
return dsnToString(dsn);
78-
}
79-
8052
interface AWSLambdaOptions extends Sentry.NodeOptions {
8153
/**
8254
* Internal field that is set to `true` when init() is called by the Sentry AWS Lambda layer.
@@ -106,12 +78,6 @@ export function init(options: AWSLambdaOptions = {}): void {
10678
version: Sentry.SDK_VERSION,
10779
};
10880

109-
// If invoked by the Sentry Lambda Layer point the SDK to the Lambda Extension (inside the layer) instead of the host
110-
// specified in the DSN
111-
if (options._invokedByLambdaLayer) {
112-
options.dsn = extensionRelayDSN(options.dsn);
113-
}
114-
11581
Sentry.init(options);
11682
Sentry.addGlobalEventProcessor(serverlessEventProcessor);
11783
}

packages/serverless/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"compilerOptions": {
77
// package-specific options
8-
"target": "ES2018"
8+
"target": "ES2018",
9+
"resolveJsonModule": true
910
}
1011
}

scripts/aws-delete-local-layers.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Deletes all versions of the layer specified in LAYER_NAME in one region.
4+
#
5+
6+
set -euo pipefail
7+
8+
# override default AWS region
9+
export AWS_REGION=eu-central-1
10+
11+
LAYER_NAME=SentryNodeServerlessSDK-local-dev
12+
VERSION="0"
13+
14+
while [[ $VERSION != "1" ]]
15+
do
16+
VERSION=$(aws lambda list-layer-versions --layer-name $LAYER_NAME | jq '.LayerVersions[0].Version')
17+
aws lambda delete-layer-version --layer-name $LAYER_NAME --version-number $VERSION
18+
done

scripts/aws-deploy-local-layer.sh

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,23 @@ rm -rf dist-serverless/
1616
rm -rf ./packages/serverless/build
1717
rm -rf ./packages/serverless/dist
1818
rm -rf ./packages/serverless/node_modules
19-
rm -f sentry-node-serverless-*.zip
2019

2120
# Creating Lambda layer
2221
echo "Creating Lambda layer in ./packages/serverless/build/aws/dist-serverless..."
2322
cd packages/serverless
2423
yarn build
25-
cd ../../
2624
echo "Done creating Lambda layer in ./packages/serverless/build/aws/dist-serverless."
2725

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-
echo "Downloading relay..."
41-
# Make directory (if not existing)
42-
mkdir -p dist-serverless/relay
43-
# Download releay from release registry to dist-serverless/relay/relay
44-
curl -0 --silent \
45-
--output dist-serverless/relay/relay \
46-
"$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)"
47-
# Make file executable
48-
chmod +x dist-serverless/relay/relay
49-
echo "Done downloading relay."
50-
51-
echo "Creating start script..."
52-
# Make directory (if not existing)
53-
mkdir -p dist-serverless/extensions
54-
# Create 'sentry-lambda-extension' script that starts relay.
55-
# The file has to have exactly this name, because the executable files of
56-
# Lambda extensions need to have same file name as the name that they use
57-
# to register with AWS Lambda environment
58-
cat > dist-serverless/extensions/sentry-lambda-extension << EOT
59-
#!/bin/bash
60-
set -euo pipefail
61-
exec /opt/relay/relay run \
62-
--mode=proxy \
63-
--shutdown-timeout=2 \
64-
--upstream-dsn="\$SENTRY_DSN" \
65-
--aws-runtime-api="\$AWS_LAMBDA_RUNTIME_API"
66-
EOT
67-
# Make script executable
68-
chmod +x dist-serverless/extensions/sentry-lambda-extension
69-
echo "Done creating start script."
70-
71-
# Zip Lambda layer and included Lambda extension
72-
echo "Zipping Lambda layer and included Lambda extension..."
73-
cd dist-serverless/
74-
zip -r -y ../sentry-node-serverless-x.x.x-dev.zip .
75-
cd ..
76-
echo "Done Zipping Lambda layer and included Lambda extension to ./sentry-node-serverless-x.x.x-dev.zip."
77-
7826
# Deploying zipped Lambda layer to AWS
79-
echo "Deploying zipped Lambda layer to AWS..."
27+
ZIP=$(ls build/aws/dist-serverless | grep sentry-node-serverless | head -n 1)
28+
echo "Deploying zipped Lambda layer $ZIP to AWS..."
8029

8130
aws lambda publish-layer-version \
8231
--layer-name "SentryNodeServerlessSDK-local-dev" \
8332
--region "eu-central-1" \
84-
--zip-file "fileb://sentry-node-serverless-x.x.x-dev.zip" \
33+
--zip-file "fileb://build/aws/dist-serverless/$ZIP" \
8534
--description "Local test build of SentryNodeServerlessSDK (can be deleted)" \
86-
--no-cli-pager
35+
--compatible-runtimes nodejs10.x nodejs12.x nodejs14.x nodejs16.x nodejs18.x
8736

8837
echo "Done deploying zipped Lambda layer to AWS as 'SentryNodeServerlessSDK-local-dev'."
8938

0 commit comments

Comments
 (0)