Created
March 11, 2012 15:22
-
-
Save okochang/2016796 to your computer and use it in GitHub Desktop.
Set the same permit rule to multiple security groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
## 複数のセキュリティグループに同一の許可ルールを設定します | |
## スクリプトの引数には設定するセキュリティグループを指定します | |
require 'aws-sdk' | |
# 設定するプロトコルや接続元のIPアドレスを設定する | |
protocol = 'set tcp or udp or icmp' | |
port = 'set port number' | |
source = 'set source ip address' | |
# 指定された引数を変数に格納する | |
sg_array = ARGV | |
# AWSの認証情報、リージョンを指定してログインします | |
ACCESS_KEY = 'YOUR_ACCESS_KEY' | |
SECRET_KEY = 'YOUR_SECRET_KEY' | |
REGION = 'ec2.ap-northeast-1.amazonaws.com' | |
AWS.config(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY, :ec2_endpoint => REGION) | |
ec2 = AWS::EC2.new | |
# 変更対象のグループをループして許可ルールを追加していく | |
sg_array.each do |sg_name| | |
sg = ec2.security_groups.filter('group-name', sg_name).first | |
sg.authorize_ingress(protocol.to_sym, port, source) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment