0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Boto3を使ってAMIのNameのリスト一覧を取得してみた

Posted at

Boto3を利用してAMIの一覧をリストで取得する処理を作成しました。
Owner_idにユーザのOwnerIDを入れると動きます。

リストの使い方などなんとなく覚えてきました。
for文で必要なところを抜き出してますが、もっと素敵があるとうれしいなと思います。

AWSのLambdaバージョンにすれば環境変数でOwnerIDも指定出来るので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 = "ここにIDをいれる"

# 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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?