AWS SDKを使ったアプリケーションを作る時credentialsの扱いがいつも面倒なので、ベストプラクティス的なものを考えていきたい。
例として、
$ ruby myec2.rb list
ruby_block "add %D to LogFormat" do | |
path = "/etc/httpd/conf/httpd.conf" | |
content = File.read path | |
notifies :restart, "service[httpd]" | |
not_if do | |
content.match /^LogFormat.*%D.*combined$/ | |
end | |
block do |
ruby -e 'Dir.glob("#{Dir.pwd}/nodes/*").to_a.map {|path| path.match(/nodes\/(.+)\.json/)[1]}.each {|node| system "bundle exec knife solo cook #{node}"}' |
require "net/http" | |
require "aws-sdk" | |
require "aws_config" | |
def own_region | |
begin | |
timeout 3 do | |
Net::HTTP.get("169.254.169.254", "/latest/meta-data/placement/availability-zone").chop | |
end | |
rescue |
# Description: | |
# Shibame is the yet another important thing in your life | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# Export your Flickr API key to environmental variable FLICKR_API_KEY | |
# | |
# Commands: |
test `ssh-keygen -y -f id_rsa | cut -f 2 -d " "` = `cat id_rsa.pub | cut -f 2 -d " "` ; echo $? | |
# 0なら一致 |
だいぶ前に作って放置していたRubygem backlog_jp を Backlog.jp API V2 に対応する形でほぼ作り直した。使い方はREADMEを参照。
以前のバージョンではオブジェクト指向的に課題を操作したりできるようにしようと意気込んではいたものの途中で飽きてしまい、中途半端な状態で放置してしまったので今バージョンは本当に薄いラッパーという感じに。
実装例として、プロジェクト内の全課題とそれについているコメントをJSONにexportするツール backlog_jp-pj2json も作った。
テストコードも書いてなく粗末な出来ですが、物好きな方はご利用ください。
Vagrant.configure 2 do |config| | |
config.vm.box = "dummy" | |
config.vm.provider :aws do |aws, override| | |
aws.access_key_id = "NAZONOMOJIRETSU" | |
aws.secret_access_key = "mottonagainazonomojiretsu" | |
aws.region = "ap-northeast-1" | |
aws.keypair_name = "orenokey" | |
aws.ami = "ami-4985b048" |
require "thor" | |
require "aws-sdk-resources" | |
class OrenoAwsTool < Thor | |
class_option :profile, | |
desc: "Load credentials by profile name from shared credentials file (~/.aws/credentials).", | |
aliases: [:p] | |
class_option :access_key_id, | |
desc: "AWS access key id.", |