This is the script used to find out the Image ID of the AMI used by AWS Data Pipeline.
import boto3
from time import sleep
session = boto3.Session(profile_name="{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():
"""If you do not specify a marker, it will end in the middle
"""
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()
Recommended Posts