I created a process to get a list of AMIs using Boto3. It works if you put the owner ID of the user in Owner_id.
I somehow learned how to use the list. I've extracted the necessary parts in the for statement, but I'd be happy if there was something more wonderful.
If you use the Lambda version of AWS, you can also specify the Owner ID in the environment variable, so it is easy to publish with Git ...
# -*- coding: utf-8 -*-
# import
import boto3
from boto3.session import Session
from datetime import date, datetime, timedelta
ec2 = boto3.client('ec2')
list_ami = []
Owner_id = "Enter your ID here"
# def
def get_list_ami():
response = ec2.describe_images(
Owners = [Owner_id]
)
for list_id in response['Images']:
list_ami.append(list_id['Name'])
return list_ami
# Main
if __name__ == "__main__":
get_list_ami()
print list_ami
https://github.com/handa3/study/blob/master/aws/ec2/get_list_ami.py
Recommended Posts