To get the AWS Region where your Lambda Function is running we need to access the Environment Variable AWS_REGION
.
To access the environment variable AWS_REGION
using Node.js Lambda Function we can use process.env.AWS_REGION
.
Example of Node.js Lambda Function getting the Runtime Region
I launched a Lambda Function in Mumbai (ap-south-1) region and used the following javascript code.
exports.handler = async (event) => {
const region_code = process.env.AWS_REGION;
console.log(region_code);
};
Output
If you want to learn more on how to get Environment Variables in Node.js Lambda Functions visit my article about it here.
I hope this helps.