简体   繁体   English

使用Chef列出AWS快照

[英]List AWS snapshots using chef

I am looking for a solution to list all AWS snapshots in chef and pick the latest one. 我正在寻找一种解决方案,以在Chef中列出所有AWS快照并选择最新的快照。 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. 所有快照的定义都与此servername_service_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. 我将使用AWS配方,但其中没有该功能。 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 . 由于Chef只是Ruby代码,因此您可以使用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 ) 您将需要使用ruby aws SDK,并需要确定将要使用的ruby SDK的各个部分(提示其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. 利用AWS Cookbook(已经包含AWS开发工具包),您可以搭载该功能以使用您自己的功能对其进行扩展。

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) 我的建议:只需创建一些获取此数据并填充您的厨师查询(快照列表)(也许只是在环境中填充json或包含快照列表的对象)(一些外部k / v存储,例如consul to存储调查结果等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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