问题
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