Skip to content
Advertisement

AWS region in AWS Glue

How can I get the region in which the current Glue job is executing?


When the Glue job starts executing, I see the output

Detected region eu-central-1.

In AWS Lambda, I can use the following lines to fetch the current region:

JavaScript

However, it seems like the AWS_REGION environment variable is not present in Glue and therefore a KeyError is raised:

KeyError: 'AWS_REGION'


The reason why I need the region is I am trying to fetch all databases and tables as described in this question and I do not want to hard code the region when creating the boto client.

Advertisement

Answer

One option is to pass the AWS_REGION as a job parameter. For example, if you trigger the job from Lambda:

JavaScript

Alternatively, if you define your jobs using the AWS::Glue::Job CloudFormation resource:

JavaScript

Then you can extract the AWS_REGION parameter in your job code using getResolvedOptions:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement