Skip to content

Commit e031f9a

Browse files
mlaversGitHub Enterprise
authored andcommitted
Merge pull request #1 from aws-lambda/mlavers/lambda-808
Add Lambda Extension to Layers
2 parents 000b496 + 8365c10 commit e031f9a

File tree

4 files changed

+148
-15
lines changed

4 files changed

+148
-15
lines changed

.circleci/config.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ jobs:
9595
cd python
9696
./publish-layers.sh python3.8
9797
98+
publish-extension:
99+
docker:
100+
- image: circleci/python:3.8
101+
steps:
102+
- checkout
103+
- run:
104+
name: Install publish dependencies
105+
command: sudo pip install -U awscli
106+
- run:
107+
name: Publish layer
108+
command: |
109+
cd extension
110+
./publish-layer.sh
111+
98112
workflows:
99113
version: 2
100114
publish-layers:
@@ -141,3 +155,9 @@ workflows:
141155
ignore: /.*/
142156
tags:
143157
only: /v[0-9]+(\.[0-9]+)*_python/
158+
- publish-extension:
159+
filters:
160+
branches:
161+
ignore: /.*/
162+
tags:
163+
only: /v[0-9]+(\.[0-9]+)*_extension/

extension/publish-layer.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash -x
2+
3+
BUCKET_PREFIX=nr-layers
4+
5+
EXTENSION_DIST_URL=https://github.com/newrelic/newrelic-lambda-extension/archive/v1.0.0.zip
6+
EXTENSION_DIST_ZIP=extension.zip
7+
8+
REGIONS=(
9+
ap-northeast-1
10+
ap-northeast-2
11+
ap-south-1
12+
ap-southeast-1
13+
ap-southeast-2
14+
ca-central-1
15+
eu-central-1
16+
eu-west-1
17+
eu-west-2
18+
eu-west-3
19+
sa-east-1
20+
us-east-1
21+
us-east-2
22+
us-west-1
23+
us-west-2
24+
)
25+
26+
function build-layer {
27+
echo "Building New Relic Lambda Extension Layer"
28+
rm -rf $EXTENSION_DIST_ZIP
29+
curl $EXTENSION_DIST_URL -o $EXTENSION_DIST_ZIP
30+
echo "Build complete: ${EXTENSION_DIST_ZIP}"
31+
}
32+
33+
function publish-layer {
34+
if [ ! -f $EXTENSION_DIST_ZIP ]; then
35+
echo "Package not found: ${EXTENSION_DIST_ZIP}"
36+
exit 1
37+
fi
38+
39+
layer_hash=$(md5sum $EXTENSION_DIST_ZIP | awk '{ print $1 }')
40+
layer_s3key="nr-extension/${layer_hash}.zip"
41+
42+
for region in "${REGIONS[@]}"; do
43+
bucket_name="${BUCKET_PREFIX}-${region}"
44+
45+
echo "Uploading ${EXTENSION_DIST_ZIP} to s3://${bucket_name}/${layer_s3key}"
46+
aws --region $region s3 cp $EXTENSION_DIST_ZIP "s3://${bucket_name}/${layer_s3key}"
47+
48+
echo "Publishing extension layer to ${region}"
49+
layer_version=$(aws lambda publish-layer-version \
50+
--layer-name NewRelicLambdaExtension \
51+
--content "S3Bucket=${bucket_name},S3Key=${layer_s3key}" \
52+
--description "New Relic Lambda Extension Layer" \
53+
--license-info "Apache-2.0" \
54+
--compatible-runtimes dotnetcore1.0 dotnetcore2.0 dotnetcore2.1 dotnetcore3.1 nodejs nodejs8.10 nodejs10.x nodejs12.x go1.x java8 java11 provided python2.7 python3.6 python3.7 python3.8 ruby2.5 ruby2.7 \
55+
--region $region \
56+
--output text \
57+
--query Version)
58+
echo "Published layer version ${layer_version} to ${region}"
59+
60+
echo "Setting public permissions for layer version ${layer_version} in ${region}"
61+
aws lambda add-layer-version-permission \
62+
--layer-name NewRelicLambdaExtension \
63+
--version-number $layer_version \
64+
--statement-id public \
65+
--action lambda:GetLayerVersion \
66+
--principal "*" \
67+
--region $region
68+
echo "Public permissions set for layer version ${layer_version} in region ${region}"
69+
done
70+
}
71+
72+
case "$1" in
73+
*)
74+
build-layer
75+
publish-layer
76+
;;
77+
esac

nodejs/publish-layers.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ NJS810_DIST=$DIST_DIR/nodejs810.zip
77
NJS10X_DIST=$DIST_DIR/nodejs10x.zip
88
NJS12X_DIST=$DIST_DIR/nodejs12x.zip
99

10+
EXTENSION_DIST_DIR=extensions
11+
EXTENSION_DIST_URL=https://github.com/newrelic/newrelic-lambda-extension/archive/v1.0.0.zip
12+
EXTENSION_DIST_ZIP=extension.zip
13+
1014
REGIONS=(
1115
ap-northeast-1
1216
ap-northeast-2
@@ -29,15 +33,23 @@ function usage {
2933
echo "./publish-layers.sh [nodejs8.10|nodejs10.x|nodejs12.x]"
3034
}
3135

36+
function download-extension {
37+
rm -rf $EXTENSION_DIST_DIR $EXTENSION_DIST_ZIP
38+
curl $EXTENSION_DIST_URL -o $EXTENSION_DIST_ZIP
39+
unzip $EXTENSION_DIST_ZIP -d .
40+
rm -f $EXTENSION_DIST_ZIP
41+
}
42+
3243
function build-nodejs810 {
3344
echo "Building New Relic layer for nodejs8.10"
3445
rm -rf $BUILD_DIR $NJS810_DIST
3546
mkdir -p $DIST_DIR
3647
npm install --prefix $BUILD_DIR newrelic@latest @newrelic/aws-sdk@latest
3748
mkdir -p $BUILD_DIR/node_modules/newrelic-lambda-wrapper
3849
cp index.js $BUILD_DIR/node_modules/newrelic-lambda-wrapper
39-
zip -rq $NJS810_DIST $BUILD_DIR
40-
rm -rf $BUILD_DIR
50+
download-extension
51+
zip -rq $NJS810_DIST $BUILD_DIR $EXTENSION_DIST_DIR
52+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
4153
echo "Build complete: ${NJS810_DIST}"
4254
}
4355

@@ -61,6 +73,7 @@ function publish-nodejs810 {
6173
--layer-name NewRelicNodeJS810 \
6274
--content "S3Bucket=${bucket_name},S3Key=${njs810_s3key}" \
6375
--description "New Relic Layer for Node.js 8.10" \
76+
--license-info "Apache-2.0" \
6477
--compatible-runtimes nodejs8.10 \
6578
--region $region \
6679
--output text \
@@ -86,8 +99,9 @@ function build-nodejs10x {
8699
npm install --prefix $BUILD_DIR newrelic@latest @newrelic/aws-sdk@latest
87100
mkdir -p $BUILD_DIR/node_modules/newrelic-lambda-wrapper
88101
cp index.js $BUILD_DIR/node_modules/newrelic-lambda-wrapper
89-
zip -rq $NJS10X_DIST $BUILD_DIR
90-
rm -rf $BUILD_DIR
102+
download-extension
103+
zip -rq $NJS10X_DIST $BUILD_DIR $EXTENSION_DIST_DIR
104+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
91105
echo "Build complete: ${NJS10X_DIST}"
92106
}
93107

@@ -111,6 +125,7 @@ function publish-nodejs10x {
111125
--layer-name NewRelicNodeJS10X \
112126
--content "S3Bucket=${bucket_name},S3Key=${njs10x_s3key}" \
113127
--description "New Relic Layer for Node.js 10.x" \
128+
--license-info "Apache-2.0" \
114129
--compatible-runtimes nodejs10.x \
115130
--region $region \
116131
--output text \
@@ -136,8 +151,9 @@ function build-nodejs12x {
136151
npm install --prefix $BUILD_DIR newrelic@latest @newrelic/aws-sdk@latest
137152
mkdir -p $BUILD_DIR/node_modules/newrelic-lambda-wrapper
138153
cp index.js $BUILD_DIR/node_modules/newrelic-lambda-wrapper
139-
zip -rq $NJS12X_DIST $BUILD_DIR
140-
rm -rf $BUILD_DIR
154+
download-extension
155+
zip -rq $NJS12X_DIST $BUILD_DIR $EXTENSION_DIST_DIR
156+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
141157
echo "Build complete: ${NJS12X_DIST}"
142158
}
143159

@@ -161,6 +177,7 @@ function publish-nodejs12x {
161177
--layer-name NewRelicNodeJS12X \
162178
--content "S3Bucket=${bucket_name},S3Key=${njs12x_s3key}" \
163179
--description "New Relic Layer for Node.js 12.x" \
180+
--license-info "Apache-2.0" \
164181
--compatible-runtimes nodejs12.x \
165182
--region $region \
166183
--output text \

python/publish-layers.sh

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PY36_DIST=$DIST_DIR/python36.zip
88
PY37_DIST=dist/python37.zip
99
PY38_DIST=dist/python38.zip
1010

11+
EXTENSION_DIST_DIR=extensions
12+
EXTENSION_DIST_URL=https://github.com/newrelic/newrelic-lambda-extension/archive/v1.0.0.zip
13+
EXTENSION_DIST_ZIP=extension.zip
14+
1115
REGIONS=(
1216
ap-northeast-1
1317
ap-northeast-2
@@ -30,15 +34,23 @@ function usage {
3034
echo "./publish-layers.sh [python2.7|python3.6|python3.7|python3.8]"
3135
}
3236

37+
function download-extension {
38+
rm -rf $EXTENSION_DIST_DIR $EXTENSION_DIST_ZIP
39+
curl $EXTENSION_DIST_URL -o $EXTENSION_DIST_ZIP
40+
unzip $EXTENSION_DIST_ZIP -d .
41+
rm -f $EXTENSION_DIST_ZIP
42+
}
43+
3344
function build-python27 {
3445
echo "Building New Relic layer for python2.7"
35-
rm -rf $BUILD_DIR $PY27_DIST
46+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR $PY27_DIST
3647
mkdir -p $DIST_DIR
3748
pip install --no-cache-dir -qU newrelic newrelic-lambda -t $BUILD_DIR/lib/python2.7/site-packages
3849
cp newrelic_lambda_wrapper.py $BUILD_DIR/lib/python2.7/site-packages/newrelic_lambda_wrapper.py
3950
find $BUILD_DIR -name '*.pyc' -exec rm -f {} +
40-
zip -rq $PY27_DIST $BUILD_DIR
41-
rm -rf $BUILD_DIR
51+
download-extension
52+
zip -rq $PY27_DIST $BUILD_DIR $EXTENSION_DIST_DIR
53+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
4254
echo "Build complete: ${PY27_DIST}"
4355
}
4456

@@ -62,6 +74,7 @@ function publish-python27 {
6274
--layer-name NewRelicPython27 \
6375
--content "S3Bucket=${bucket_name},S3Key=${py27_s3key}" \
6476
--description "New Relic Layer for Python 2.7" \
77+
--license-info "Apache-2.0" \
6578
--compatible-runtimes python2.7 \
6679
--region $region \
6780
--output text \
@@ -87,8 +100,9 @@ function build-python36 {
87100
pip install --no-cache-dir -qU newrelic newrelic-lambda -t $BUILD_DIR/lib/python3.6/site-packages
88101
cp newrelic_lambda_wrapper.py $BUILD_DIR/lib/python3.6/site-packages/newrelic_lambda_wrapper.py
89102
find $BUILD_DIR -name '__pycache__' -exec rm -rf {} +
90-
zip -rq $PY36_DIST $BUILD_DIR
91-
rm -rf $BUILD_DIR
103+
download-extension
104+
zip -rq $PY36_DIST $BUILD_DIR $EXTENSION_DIST_DIR
105+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
92106
echo "Build complete: ${PY36_DIST}"
93107
}
94108

@@ -112,6 +126,7 @@ function publish-python36 {
112126
--layer-name NewRelicPython36 \
113127
--content "S3Bucket=${bucket_name},S3Key=${py36_s3key}" \
114128
--description "New Relic Layer for Python 3.6" \
129+
--license-info "Apache-2.0" \
115130
--compatible-runtimes python3.6 \
116131
--region $region \
117132
--output text \
@@ -137,8 +152,9 @@ function build-python37 {
137152
pip install --no-cache-dir -qU newrelic newrelic-lambda -t $BUILD_DIR/lib/python3.7/site-packages
138153
cp newrelic_lambda_wrapper.py $BUILD_DIR/lib/python3.7/site-packages/newrelic_lambda_wrapper.py
139154
find $BUILD_DIR -name '__pycache__' -exec rm -rf {} +
140-
zip -rq $PY37_DIST $BUILD_DIR
141-
rm -rf $BUILD_DIR
155+
download-extension
156+
zip -rq $PY37_DIST $BUILD_DIR $EXTENSION_DIST_DIR
157+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
142158
echo "Build complete: ${PY37_DIST}"
143159
}
144160

@@ -162,6 +178,7 @@ function publish-python37 {
162178
--layer-name NewRelicPython37 \
163179
--content "S3Bucket=${bucket_name},S3Key=${py37_s3key}" \
164180
--description "New Relic Layer for Python 3.7" \
181+
--license-info "Apache-2.0" \
165182
--compatible-runtimes python3.7 \
166183
--region $region \
167184
--output text \
@@ -187,8 +204,9 @@ function build-python38 {
187204
pip install --no-cache-dir -qU newrelic newrelic-lambda -t $BUILD_DIR/lib/python3.8/site-packages
188205
cp newrelic_lambda_wrapper.py $BUILD_DIR/lib/python3.8/site-packages/newrelic_lambda_wrapper.py
189206
find $BUILD_DIR -name '__pycache__' -exec rm -rf {} +
190-
zip -rq $PY38_DIST $BUILD_DIR
191-
rm -rf $BUILD_DIR
207+
download-extension
208+
zip -rq $PY38_DIST $BUILD_DIR $EXTENSION_DIST_DIR
209+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR
192210
echo "Build complete: ${PY38_DIST}"
193211
}
194212

@@ -212,6 +230,7 @@ function publish-python38 {
212230
--layer-name NewRelicPython38 \
213231
--content "S3Bucket=${bucket_name},S3Key=${py38_s3key}" \
214232
--description "New Relic Layer for Python 3.8" \
233+
--license-info "Apache-2.0" \
215234
--compatible-runtimes python3.8 \
216235
--region $region \
217236
--output text \

0 commit comments

Comments
 (0)