This is a test API used to demonstrate issue 3756 on the Elastic APM agent for NodeJS.
What follows is a step-by-step guide on how to deploy the function code through AWS Console. For this you only need the compiled JS file lambda/index.js
and this README.md
, however the entire project is supplied as well for reference.
- Go to Lambda and Press "Create Function"
- Pick "Author from scratch"
- Enter a function name, e.g. "thorhj-lambda-apm-test"
- Pick runtime "Node.js 20.x"
- Pick architecture "x86_64"
- Press "Create function"
- Go to the Code tab
- Open "index.mjs"
- Copy the contents of
/lambda/index.js
in this project to the function fileindex.mjs
- Rename
index.mjs
toindex.js
- Press "Deploy" to update the function code
Add the two Elastic APM layers to the Lambda using this guide: https://www.elastic.co/guide/en/apm/agent/nodejs/current/lambda.html
Add the following environment variables to the Lambda function:
NODE_OPTIONS: -r elastic-apm-node/start
ELASTIC_APM_ENVIRONMENT: development
ELASTIC_APM_LOG_LEVEL: warning
ELASTIC_APM_SEND_STRATEGY: background
ELASTIC_APM_SERVICE_NAME: thorhj-lambda-apm-test
ELASTIC_APM_LAMBDA_APM_SERVER: <your apm server url>
ELASTIC_APM_SECRET_TOKEN: <your apm secret token>
More details: https://www.elastic.co/guide/en/apm/agent/nodejs/current/lambda.html
- Create API
- Create REST API
- New API
Create resource/method
- Create resource
- Enable "Proxy resouce"
- Resource name "api-test"
- Press "Create resource"
- Create another resource
- Enable "Proxy resource"
- Use Resource path "/api-test/"
- Use resource name "{proxy+}"
- Press "Create resource"
- Click on the ANY method under {proxy+}
- Click "Edit integration"
- Integration type "Lambda Proxy"
- Enable "Lambda proxy integration"
- Select the Lambda function
- Press "Save"
- Press "Deploy API", use "v1" as stage (this must be included in the HTTP request)
AWS environment variables:
Get the invoke URL for the API Gateway. Use this URL and make a GET request to
https://<your api gateway id>.execute-api.eu-central-1.amazonaws.com/v1/api-test/ok
and
https://<your api gateway id>.execute-api.eu-central-1.amazonaws.com/v1/api-test/error
When the APM data is collected, both of these requests will show up under the transaction GET /v1/api-test/{proxy+}
.