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 1 year has passed since last update.

AWS Data Pipelineで利用しているAMIをリストアップする

Last updated at Posted at 2020-12-24

AWS DataPipelineで利用しているAMIのImage IDを調べるために使ったスクリプトです。

import boto3
from time import sleep

session = boto3.Session(profile_name="{プロファイル名}")
client = session.client("datapipeline")


def main():
    for x in list_all_pipelines():
        for i in get_ec2_resources(x):
            print(x, i)


def list_all_pipelines():
    """markerを指定しないと途中で終わってしまう
    """
    result = client.list_pipelines()
    pipelines = [x["id"] for x in result["pipelineIdList"]]
    marker = result["marker"]
    while marker is not None:
        y = client.list_pipelines(marker=marker)
        pipelines += [x["id"] for x in y["pipelineIdList"]]
        marker = y.get("marker", None)
    return pipelines


def get_ec2_resources(pipeline_id):
    resources = []
    result = client.get_pipeline_definition(pipelineId=pipeline_id)
    for x in result["pipelineObjects"]:
        if x["name"] == "Ec2":
            for y in x["fields"]:
                if y["key"] == "imageId":
                    resources.append(y["stringValue"])
    return resources


if __name__ == "__main__":
    main()
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?