Regions.getCurrentRegion()
returns null from within an AWS Lambda function. It seems that Regions.getCurrentRegion()
is not supported from within an AWS Lambda function. Is there an alternative way to determine which region the lambda function is running in?
NOTE: AWS Lambda function is written in Java.
You can read the AWS_REGION
environment variable and use the Regions.fromName
function to parse that into a useable region.
Regions.fromName(System.getenv("AWS_REGION"))
The advantage of this over the ARN parsing approach is that you do not need a Context object which means you can use it outside of your handler function.