Determine aws region inside a aws glue job

久未见 提交于 2020-05-15 09:52:11

问题


Hello I need some help in determining aws region inside a glue job. I am trying to use boto3 client kms and when I do the following I get a Error NoRegionError: You must specify a region. kms = boto3.client('kms') Obviously it is asking me to set region_name when creating the client but I do not wish to hardcode the region

When running a glue job i do see a line in the logs which says Detected region us-east-2 but I am not sure on how I can fetch that value ?


回答1:


If you're running Pyspark / Python shell Glue job, try this:

import requests

r = requests.get("http://169.254.169.254/latest/dynamic/instance-identity/document")
response_json = r.json()
region = response_json.get('region')

print region



回答2:


AWS Glue is still not available in all the regions. You may refer this link

That's the reason you need to hardcode the region.

Coming to the "Detected region us-east-2" this might be becus of your aws CLI configuration



来源:https://stackoverflow.com/questions/56692091/determine-aws-region-inside-a-aws-glue-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!