https://github.com/smithclay/aws-lambda-nr-well-instrumented
AWS Lambda + AWS API Gateway + Express + New Relic Browser
https://github.com/smithclay/aws-lambda-nr-well-instrumented
Last synced: 5 months ago
JSON representation
AWS Lambda + AWS API Gateway + Express + New Relic Browser
- Host: GitHub
- URL: https://github.com/smithclay/aws-lambda-nr-well-instrumented
- Owner: smithclay
- Created: 2018-03-15T23:33:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-17T22:38:31.000Z (about 8 years ago)
- Last Synced: 2025-02-08T16:43:47.239Z (over 1 year ago)
- Language: HTML
- Size: 72.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Well-instrumented Serverless Application
### AWS Lambda + AWS API Gateway + Express + New Relic Browser
This project is designed to show instrumentation best practices for a customer-facing serverless application. It includes:
* An example Express.js application using the `aws-serverless-express` project.
* AWS CodeDeploy hooks to automatically roll back a deployment if front-end JavaScript errors are detected. (see below)
* Real-user monitoring with New Relic Browser.
* Low-volume synthetic browser traffic generated by Amazon Cloudwatch Events and a AWS Lambda function.
### context: safer deploys using real user monitoring data
With recently announced features of AWS CodeDeploy, it’s possible to gradually deploy new AWS Lambda function versions and use different lifecycle hooks to validate new function versions during deploys. Once traffic starts automatically shifting to a new function version, developers can write custom code that validates the function is working as expected. If an error or other condition is detected, the deploy can be automatically rolled back to the previous version.
For customer-facing AWS Lambda functions, it’s possible to use lifecycle hooks to validate that a new version is working correctly using real user monitoring data. This allows developers validate deploys using live production data as a final safety check before a deploy is marked as successful. This helps avoid edge cases that integration and automated test suites might not catch, like a untested particular browser version or legacy client that causes unexpected front-end errors or slow performance with new code.
This example application describes using an AWS CodeDeploy lifecycle hook with a versioned AWS Lambda function using the Serverless Application Model to validate end-users don’t experience any performance regressions or front-end errors during a new deploy.
### requirements
* AWS Account
* New Relic Account with Browser
* New Relic Insights Query Key
* `swagger.yaml` API definition file deployed to a S3 bucket specified in `template.yaml`
### additional instrumentation included
**Custom Metrics**
* Time to interactive (frontend)
* Time to hero image (frontend)
**Custom Facets**
* Deployed function version (i.e. backend deployed version)
### setup
Install dependencies:
```
$ cd express-app
$ npm install
```
```
$ cd post-traffic-hook
$ npm install
```
Set Amazon S3 bucket name to store packaged code artifacts:
```
$ export LAMBDA_BUCKET_NAME=<>
```
### packaging
Package the AWS SAM application using the [AWS SAM Local](https://github.com/awslabs/aws-sam-local) tool:
```
$ sam package --template-file template.yaml --s3-bucket $LAMBDA_BUCKET_NAME --output-template-file packaged.yaml
```
### deploying
A New Relic account and [New Relic Insights Query Key](https://docs.newrelic.com/docs/insights/insights-api/get-data/query-insights-event-data-api) is required.
```
$ sam deploy --template-file ./packaged.yaml --stack-name lambda-stack-postdeploy --capabilities CAPABILITY_NAMED_IAM --parameter-overrides "NRAccountId=<>" "NRInsightsQueryKey=<>"
```