I tried to get a list of AMI Names using Boto3

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

I tried to get a list of AMI Names using Boto3
I tried to get a database of horse racing using Pandas
I tried to get the index of the list using the enumerate function
I tried to get an AMI using AWS Lambda
I tried to make a regular expression of "amount" using Python
I tried to make a regular expression of "time" using Python
I tried to create a list of prime numbers with python
I tried to make a regular expression of "date" using Python
[Python / DynamoDB / boto3] List of operations I tried
Get a list of IAM users with Boto3
I tried to make a ○ ✕ game using TensorFlow
I tried to get the batting results of Hachinai using image processing
I tried to perform a cluster analysis of customers using purchasing data
[Python] I tried to get Json of squid ring 2
I tried using Python (3) instead of a scientific calculator
I tried to draw a configuration diagram using Diagrams
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I want to collect a lot of images, so I tried using "google image download"
[Command] Command to get a list of files containing double-byte characters
I tried to get Web information using "Requests" and "lxml"
Since Python 1.5 of Discord, I can't get a list of members
I tried "How to get a method decorated in Python"
I tried adding post-increment to CPython. List of all changes
I tried to get started with Hy ・ Define a class
How to get a list of built-in exceptions in python
I tried to automate [a certain task] using Raspberry Pi
I tried to make a stopwatch using tkinter in python
How to get a list of links from a page from wikipedia
I tried to make a simple text editor using PyQt
I tried to get data from AS / 400 quickly using pypyodbc
I tried using GrabCut of OpenCV
I tried to compare the accuracy of machine learning models using kaggle as a theme.
I tried to create a Python script to get the value of a cell in Microsoft Excel
I tried using PI Fu to generate a 3D model of a person from one image
I tried to automate the construction of a hands-on environment using IBM Cloud's SoftLayer API
Try to get a list of breaking news threads in Python.
A memorandum when I tried to get it automatically with selenium
I tried to implement anomaly detection using a hidden Markov model
I tried to make a todo application using bottle with python
How to get a list excluding elements whose index is i ...?
[Python] I tried to get various information using YouTube Data API!
I tried to get data from AS / 400 quickly using pypyodbc Preparation 1
I tried to make a mechanism of exclusive control with Go
I tried to create a linebot (implementation)
I tried to create a linebot (preparation)
I tried to get started with Hy
I tried playing a ○ ✕ game using TensorFlow
I tried drawing a line using turtle
I tried to classify text using TensorFlow
[python] Get a list of instance variables
I tried to make a Web API
I tried using pipenv, so a memo
[Python] Get a list of folders only
I tried 3D detection of a car
I tried to predict Covid-19 using Darts
I tried to estimate the similarity of the question intent using gensim's Doc2Vec
[Linux] Command to get a list of commands executed in the past
I measured 6 methods to get the index of the maximum value (minimum value) of the list
I tried to get the authentication code of Qiita API with Python.
I want to sort a list in the order of other lists
I tried to extract and illustrate the stage of the story using COTOHA