简体   繁体   中英

List AWS snapshots using chef

I am looking for a solution to list all AWS snapshots in chef and pick the latest one. All the snapshots are defined like this servername_service_date and I would like to list them via date and then let the server pick the latest one by date. So it will create the volume from that snapshot. I will be using AWS recipe, but they do not have the feature in it. So I would like to have some tips how to make it happen not a full code of course (if someone does not have it already). I hope you guys can help me.

Since Chef is just Ruby code, you could easily write a simple library using the AWS Ruby gem . For example:

AWS.ec2.snapshots #=> #<SnapshotCollection>

you will need the ruby aws SDK you will need to identify the sections of the ruby SDK you will be leveraging (hint its ec2: https://docs.aws.amazon.com/sdkforruby/api/Aws/EC2.html )

you will need to instantiate a connector

ec2 = Aws::EC2::Client.new(region: 'us-east-1')

then you will do the specifics of your operation.. just be cautious adding random things to chef that work this way!

Leveraging the AWS cookbook (which already has the AWS SDK included) you could piggyback that functionality to extend it with your own.

My suggestion: just create something that gets this data and populates your chef lookups (a list of your snapshots) (maybe just populate json in an environment or something that has the list of your snapshots) (some external k/v store like consul to store the findings etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM