[英]How can I get the AMI Id through the AMI name with boto3?
我正在嘗試使用已經部署和運行的 EC2 實例自動創建自動縮放組 Cloudformation 模板,因此,為了制作精確的副本,我需要擁有當前實例的 AMI。 為了獲得圖像,我運行以下腳本:
ec2 = boto3.client('ec2')
ec2.create_image(InstanceId="i-f234nr1kdd", Name="abc")
它有效,現在我需要使用 boto3 獲取 AMI Id 和 AMI 名稱,以便將 AMI Id 傳遞給 cloudformation 模板。
我只需要以 AMI 名稱作為參數以編程方式獲取 AMI id 值,以便將 AMI Id 傳遞給生成 Cloudformation 模板的代碼部分
從現在開始感謝!
response = ec2.create_image(InstanceId="i-f234nr1kdd", Name="abc")
response('ImageId')
此處的文檔: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.create_image表明 AMI 的 id 在方法返回的字典中稱呼。
它應該是response["ImageId"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.