Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #
- #
- # 自分が所有するSnapShotで、AMIがないものを探索するスクリプトです。
- # 要 AWS SDK for Ruby V2
- #
- require 'aws-sdk-core'
- require 'yaml'
- require 'pp'
- config=YAML.load(File.read("config.yml"))
- Aws.config[:credentials] = Aws::Credentials.new(config['access_key_id'],config['secret_access_key'])
- ec2=Aws::EC2::Client.new(region:config['region'])
- # 設定
- aws_owner_id = "<SnapShotのオーナーID>"
- ec2.describe_snapshots({ owner_ids: [aws_owner_id] }).each_page do |res|
- res.snapshots.each do | snap |
- ami_id = snap.description.match(/ami-[0-9a-zA-Z]{0,}/) # descriptionからAMIを割り出す。
- instance_id = snap.description.match(/i-[0-9a-zA-Z]{0,}/)
- if ami_id != nil
- begin
- ec2.describe_images({
- image_ids: [ami_id[0]],
- })
- rescue Aws::EC2::Errors::InvalidAMIIDNotFound
- # AMIが存在しない。
- pp "SnapShotID:#{snap.snapshot_id} is Not Found AMI #{ami_id[0]} Instance ID:#{instance_id[0]}"
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement