簡體   English   中英

python boto3-如何從函數返回中獲取值

[英]python boto3 - how to get the value from the return of a function

使用python boto3庫,我正在使用ec2.create_instances函數,該函數返回如下所示的數據:

[ec2.Instance(id ='i-34304930394309409')]

我如何簡單地提取id的值並將其放入另一個變量中? 我只想檢索“ i-34304930394394309409”並將其設置為名為“ instanceid”的變量

有沒有辦法只調用ec2.instance來檢索此值?

僅供參考:實例是從create_instances()的boto3函數返回的響應

這就是我最終解決問題的方式:

我創建了一個名為instance_id的變量,然后將其設置為instance [0] .id,這是列表中與id字符串匹配的第一個值。 不知道我是否正確解釋了...在任何情況下:

instance_id = instance[0].id
print "Instance ID:", instance_id

然后,這將打印我要檢索的值:“ i-34304930394394309409”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM