In our [previous ](https://raygun.com/blog/error-reporting-aws-lambda/)article on AWS Lambda and Raygun Crash Reporting, we covered sending exception data from an AWS Lambda function written in Node.js. Recently AWS added support for [environment...
In our previous article on AWS Lambda and Raygun Crash Reporting, we covered sending exception data from an AWS Lambda function written in Node.js. Recently AWS added support for environment variables to be passed into Lambda functions. These environment variables allow you to set certain constants and then access them in your Lambda functions.
This new feature helps our customers by allowing you to specify your Raygun Crash Reporting API key in the AWS Lambda environment variables instead of hard coding it into your Lambda function. In this article I’ll be demonstrating how to setup our environment variables in AWS Lambda and then how to pass along custom data with other environment variables.
Step 1.
We will be using Node.js again for our example so the first thing we need to do is create an initial Node project. Create a new directory called awsnodeexample via command line.
mkdir awsnodeexample
Then switch to the new directory and create an index.js file to hold the sample code:
cd awsnodeexample/
touch index.js
Next, use Node Package Manager (npm) to create the Raygun Crash Reporting integration and install the necessary modules. This is the same process you would use to integrate Raygun with any Node.js application:
npm install raygun
If you are interested you can review our open source Node.js provider code in our Github repo.
Step 2.
The next step is to implement a simple function with error handling in our index.js:
// Include Raygun (note that the library and dependencies has been added to the packages directory)
var raygun = require('raygun');
exports.handler = (event, context, callback) => {
console.log('Starting');
try
{
var a = 0;
var b = a.DoSomeMagicThing();
console.log('Should never reach this');
}
catch (e) {
console.log('Sending to Raygun');
// Send the error to Raygun
var raygunClient = new raygun.Client().init({ apiKey: process.env.RAYGUN_API_KEY });
raygunClient.send(e);
}
callback(null, 'All done..');
};
Looking to Hire Professional AWS Developers? The technology inventions have demanded all businesses to use and manage cloud-based computing services and Amazon is dominating the cloud computing services provider in the world. **[Hire AWS...
Learn more about AWS Cost Allocation Tags, tag examples via the web, CLI, and node.js, explore tag compliance services, and review tagging strategies.
Want to Hire AWS Developer for cloud computing services? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, we leverage maximum benefits from the AWS platform ensuring prominent Solutions for business requirements....
India's best AWS Online Training & Certification Course By CETPA with Live Project & Avail 50% discount. Level up from creating cloud applications using AWS SDKs and to prepare for certification exams. Enroll Now!
AWS KMS is a Key Management Service that let you create Cryptographic keys that you can use to encrypt and decrypt data and also other keys. You can read more about it here.