Skip to content

Commit e6e308d

Browse files
authored
feat: Add initial dotnet Lambda layer support (newrelic#228)
* Add .NET to readme
1 parent 331c2ff commit e6e308d

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

.github/workflows/publish-dotnet.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish Dotnet Layers
2+
3+
on:
4+
push:
5+
tags:
6+
- v**_dotnet
7+
8+
jobs:
9+
publish-dotnet:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check Tag
13+
id: dotnet-check-tag
14+
run: |
15+
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+(\.[0-9]+)*_dotnet ]]; then
16+
AGENT_VERSION=$( echo ${{ github.event.ref }} | grep -Eo "[0-9]+(\.[0-9]+)*" )
17+
echo "version=$AGENT_VERSION" >> $GITHUB_OUTPUT
18+
echo "match=true" >> $GITHUB_OUTPUT
19+
fi
20+
- uses: actions/checkout@v4
21+
- name: Publish Dotnet Layer
22+
if: steps.dotnet-check-tag.outputs.match == 'true'
23+
env:
24+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
25+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
26+
AGENT_VERSION: ${{ steps.dotnet-check-tag.outputs.version }}
27+
run: |
28+
cd dotnet
29+
./publish-layers.sh

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ cd java
4343
cd ..
4444
```
4545

46+
```
47+
cd dotnet
48+
./publish-layers.sh
49+
cd ..
50+
```
51+
4652
```
4753
cd extension
4854
./publish-layer.sh
@@ -78,10 +84,15 @@ These steps will help you configure the layers correctly:
7884
* Java:
7985
* RequestHandler implementation: `com.newrelic.java.HandlerWrapper::handleRequest`
8086
* RequestStreamHandlerWrapper implementation: `com.newrelic.java.HandlerWrapper::handleStreamsRequest`
87+
* .NET: This step is not required.
8188
4. Add these environment variables to your Lambda console:
8289
* NEW_RELIC_ACCOUNT_ID: Your New Relic account ID
8390
* NEW_RELIC_LAMBDA_HANDLER: Path to your initial handler.
8491
* NEW_RELIC_USE_ESM: For Node.js handlers using ES Modules, set to `true`.
92+
* CORECLR_ENABLE_PROFILING (.NET only): 1
93+
* CORECLR_PROFILER (.NET only): {36032161-FFC0-4B61-B559-F6C5D41BAE5A}
94+
* CORECLR_NEWRELIC_HOME (.NET only): /opt/lib/newrelic-dotnet-agent
95+
* CORECLR_PROFILER_PATH (.NET only): /opt/lib/newrelic-dotnet-agent/libNewRelicProfiler.so
8596

8697
Refer to the [New Relic AWS Lambda Monitoring Documentation](https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda) for instructions on completing your configuration by linking your AWS Account and Cloudwatch Log Streams to New Relic.
8798

dotnet/publish-layers.sh

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
BUILD_DIR=lib # for .net can either be lib or bin. See: https://docs.aws.amazon.com/lambda/latest/dg/packaging-layers.html
6+
DIST_DIR=dist
7+
8+
DOTNET_DIST_ARM64=$DIST_DIR/dotnet.arm64.zip
9+
DOTNET_DIST_X86_64=$DIST_DIR/dotnet.x86_64.zip
10+
11+
AGENT_DIST_ZIP=agent.zip
12+
13+
source ../libBuild.sh
14+
15+
function usage {
16+
echo "./publish-layers.sh"
17+
}
18+
19+
function build-dotnet-x86-64 {
20+
echo "Building New Relic layer for .NET 6, 7 and 8 (x86_64)"
21+
rm -rf $BUILD_DIR $DOTNET_DIST_X86_64
22+
mkdir -p $DIST_DIR
23+
get_agent amd64
24+
# MAKE CONFIG CHANGES HERE
25+
download_extension x86_64
26+
zip -rq $DOTNET_DIST_X86_64 $BUILD_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
27+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
28+
echo "Build complete: ${DOTNET_DIST_X86_64}"
29+
}
30+
31+
function publish-dotnet-x86-64 {
32+
if [ ! -f $DOTNET_DIST_X86_64 ]; then
33+
echo "Package not found: ${DOTNET_DIST_X86_64}"
34+
exit 1
35+
fi
36+
37+
for region in "${REGIONS_X86[@]}"; do
38+
publish_layer $DOTNET_DIST_X86_64 $region dotnet x86_64
39+
done
40+
}
41+
42+
function build-dotnet-arm64 {
43+
echo "Building New Relic layer for .NET 6, 7 and 8 (ARM64)"
44+
rm -rf $BUILD_DIR $DOTNET_DIST_ARM64
45+
mkdir -p $DIST_DIR
46+
get_agent arm64
47+
# MAKE CONFIG CHANGES HERE
48+
download_extension arm64
49+
zip -rq $DOTNET_DIST_ARM64 $BUILD_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
50+
rm -rf $BUILD_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
51+
echo "Build complete: ${DOTNET_DIST_ARM64}"
52+
}
53+
54+
function publish-dotnet-arm64 {
55+
if [ ! -f $DOTNET_DIST_ARM64 ]; then
56+
echo "Package not found: ${DOTNET_DIST_ARM64}"
57+
exit 1
58+
fi
59+
60+
for region in "${REGIONS_ARM[@]}"; do
61+
publish_layer $DOTNET_DIST_ARM64 $region dotnet arm64
62+
done
63+
}
64+
65+
# exmaple https://download.newrelic.com/dot_net_agent/latest_release/newrelic-dotnet-agent_10.22.0_amd64.tar.gz
66+
function get_agent {
67+
arch=$1
68+
69+
url="https://download.newrelic.com/dot_net_agent/latest_release/newrelic-dotnet-agent_${AGENT_VERSION}_${arch}.tar.gz"
70+
rm -rf $AGENT_DIST_ZIP
71+
curl -L $url -o $AGENT_DIST_ZIP
72+
mkdir -p $BUILD_DIR
73+
tar -xvf $AGENT_DIST_ZIP -C ./$BUILD_DIR # under $BUILD_DIR/newrelic-dotnet-agent
74+
rm -f $AGENT_DIST_ZIP
75+
}
76+
77+
if [ -z $AGENT_VERSION ]; then
78+
echo "Missing required AGENT_VERSION environment variable: ${AGENT_VERSION}."
79+
exit 1
80+
fi
81+
82+
build-dotnet-arm64
83+
publish-dotnet-arm64
84+
build-dotnet-x86-64
85+
publish-dotnet-x86-64
86+

libBuild.sh

+10
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ function layer_name_str() {
134134
"ruby3.3")
135135
rt_part="Ruby33"
136136
;;
137+
"dotnet")
138+
rt_part="Dotnet"
139+
;;
137140
esac
138141

139142
case $2 in
@@ -188,6 +191,9 @@ function s3_prefix() {
188191
"ruby3.3")
189192
name="nr-ruby3.3"
190193
;;
194+
"dotnet")
195+
name="nr-dotnet"
196+
;;
191197
esac
192198

193199
echo $name
@@ -219,6 +225,10 @@ function publish_layer {
219225
then compat_list=("provided" "provided.al2" "provided.al2023" "dotnetcore3.1" "dotnet6")
220226
fi
221227

228+
if [[ $runtime_name == "dotnet" ]]
229+
then compat_list=("dotnet6" "dotnet8")
230+
fi
231+
222232
echo "Uploading ${layer_archive} to s3://${bucket_name}/${s3_key}"
223233
aws --region "$region" s3 cp $layer_archive "s3://${bucket_name}/${s3_key}"
224234

0 commit comments

Comments
 (0)