How to get the Region of a Running AWS Lambda Function using Ruby

If you need to get the Region of your running Lambda Function then you should look for the AWS_REGION in the Environment Variables.

Below is the code on how to access the AWS_REGION Environment Variable using Ruby.

aws_region = ENV['AWS_REGION']

Here is an example of a simple Ruby code where it will get the AWS region of the running Lambda Function.

def lambda_handler(event:, context:)
    aws_region = ENV['AWS_REGION']
    puts aws_region


In the example above I ran my Lambda Function in N. Virginia Region which is why the output is us-east-1.

I hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.