Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to AWS SDK for Ruby

Introduction to AWS SDK for Ruby

Isobe Kazuhiko

November 27, 2011
Tweet

More Decks by Isobe Kazuhiko

Other Decks in Technology

Transcript

  1. Introduction to AWS SDK for Ruby Introduction to AWS SDK

    for Ruby ISOBE Kazuhiko (cloudpack) JAWS-UG静岡 2011-11-27 Powered by Rabbit 1.0.4 and COZMIXNG
  2. Security Group IPアドレスを一括で置換する src_ip = 'x.x.x.x/32' dst_ip = 'y.y.y.y/32' ec2.security_groups.each

    do |src_sg| puts "#{src_sg.id}, #{src_sg.name}" src_sg.ip_permissions.each do |p| if p.ip_ranges.include? src_ip src_sg.authorize_ingress(p.protocol, p.port_range, dst_ip) src_sg.revoke_ingress(p.protocol, p.port_range, src_ip) end end end 14 36
  3. S3 期間限定URIを生成 s3 = AWS::S3.new b = s3.buckets['your-bucket-name'] o =

    b.objects['object-name'] puts o.url_for(:read, :expires => 60*60*24*31) 一ヶ月間有効なURLが生成される 15 36
  4. 最新のSnapshot as = [] ec2.volumes.each do |v| v.attachments.each do |a|

    as << a end end ss = {} r.snapshots.sort {|a,b| b.start_time <=> a.start_time }.map do |s| ss[s.volume_id] = s unless ss.include? s.volume_id end as.each do |a| vid = a.volume.id if ss.include? vid puts "#{a.instance.id} => (#{ss[vid].start_time})" end end 18 36
  5. AWS.memoize AWS.memoize do ss = {} r.snapshots.sort {|a,b| b.start_time <=>

    a.start_time }.map do |s| ss[s.volume_id] = s unless ss.include? s.volume_id end end ソートしている部分を AWS.memoizeで囲むだけ 20 36
  6. Snapshotの一覧 解決策: filter ec2.snapshots.filter( 'owner-id', 'YOUR_ACCOUNT_NUMBER').each do |s| # ...

    end 自分のアカウント番号を指定すると 自分のSnapshotのみ取得できる。 26 36