LoginSignup
1
2

More than 5 years have passed since last update.

タグでRDSやEC2インスタンスの起動、停止を自動化

Last updated at Posted at 2018-08-30

概要

Kobito.q1Pgs3.png

CloudWatchからラムダを実行して、RDSとEC2インスタンスのタグ設定をチェックします。正しくタグを設定したら自動的に起動、停止ができます

設定

ラムダを作成

  • ランタイム:Python2.7
  • 環境変数

    • TZ: Asia/Tokyo
  • ロールポリシ

    • AmazonEC2ReadOnlyAccess
    • AmazonRDSReadOnlyAccess
    • Inline policy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "ec2:StopInstances",
                "rds:StopDBInstance",
                "rds:StartDBInstance"
            ],
            "Resource": "*"
        }
    ]
}

RDS用のラムダ

ソースをコチラで参考ください
https://gist.github.com/hoangvx/a5769ef567e74541e54e27c91758c597

EC2用のラムダ

ソースをコチラで参考ください
https://gist.github.com/hoangvx/d384c9e9a084fe4620aebadd7e960477

CloudWatchの設定

Kobito.BUSfSo.png

参考

Kobito.7P9eOj.png

Ec2の設

Kobito.aWEcDK.png

RDSの設定

以上です

1
2
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
1
2