LoginSignup
3
5

More than 5 years have passed since last update.

werckerの使用するIPアドレスをSecurity Groupに登録するスクリプト

Last updated at Posted at 2016-06-07

GUIでポチポチするのが手間だったので作成。

wercker ciが使用するIPアドレスは以下から参照。
http://devcenter.wercker.com/docs/faq/what-ip-to-whitelist.html

ここのjsonが最新だそうですので、このIPのリストを登録する。
https://s3.amazonaws.com/status.wercker.com/worker_ips/production/public.json

register_whitelist.py
#coding:utf-8
import json, commands

# セキュリティーグループのID
sg_id="sg-xxxxx"

# 標準入力からwhite list ipの取得
ip_json = raw_input()
print "input json: " + ip_json

for ip in json.loads(ip_json):
    cmd="aws ec2 authorize-security-group-ingress --group-id "+ sg_id +" --cidr " + ip + "/32 --port 22 --protocol tcp"
    print commands.getstatusoutput(cmd)

実行!

$ curl https://s3.amazonaws.com/status.wercker.com/worker_ips/production/public.json | python register_whitelist.py
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5