やりたいこと 全世界のAWSのEC2からだけ許可するsecurity groupを作りたいとかそんな感じのやつ それにどれくらいの嬉しさがあるかと言うと、まぁ人それぞれだよね 以下のテンプレート部分を少し変えると、AWS WAFの定義で全世界のAWSのEC2からのアクセスを拒否するとかそういうのにも使えるよね 方法 以下のスクリプト使うとSecurity Groupの定義が一個ペロッと出力されるので後は勝手に使うといいと思います。 最大の問題は、このIPレンジは当然そのうち変わるので、本来はJSONファイルの変更を検知してlambdaを動かして最新の情報に追随させるみたいなことをやる必要があるんですが、まぁ何か雑にやりたい時はこういうのでもいいんじゃないですかね。 ちゃんとやりたい場合は以下クラスメソッドさんのエントリ参照 dev.classmethod.jp プログラム GitHub -