问题描述
您好,我需要一些帮助来确定胶水作业中的aws区域.我正在尝试使用boto3客户端kms,执行以下操作时出现错误NoRegionError: You must specify a region.
kms = boto3.client('kms')
显然,它是在创建客户端时要求我设置region_name,但我不希望对该区域进行硬编码
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 ErrorNoRegionError: 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
在执行胶水作业时,我确实在日志中看到一行显示Detected region us-east-2
,但是我不确定如何获取该值?
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 ?
推荐答案
如果您正在运行Pyspark/Python shell胶水作业,请尝试以下操作:
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
这篇关于确定aws胶水作业中的aws区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!