AWS RDSの自動起動/停止
AWS RDSの自動起動/停止参考資料 http://ghkdgh2365.blogspot.com/2020/12/aws-lambda-cloudwatch-aws-rds-how-to.html
https://aws.amazon.com/ko/premiumsupport/knowledge-center/start-stop-lambda-cloudwatch/ AWS Lambda-作成関数-保存-配置(配置)
設定→権限→ロール名のコピー→編集→タイムアウト10秒の設定
AWS IAM-ポリシーメニュー-ポリシーの作成-JSONの作成-次:タグ-次:レビュー-名前(カスタマイズ)-ポリシーの作成
「ロール」メニュー-「ロール名の貼り付け」(上図)-クリック-接続ポリシー-検索ポリシー名(カスタマイズ)-チェック-接続ポリシー
AWS CloudWatch-イベントメニュー-ルール-Amazon EventBridge-作成ルール-名前、説明-アレイ定義、スケジュール-Cron入力-ターゲット-lambda関数-選択(作成)-作成
1~1725プロセスstart図 を作成する.
https://aws.amazon.com/ko/premiumsupport/knowledge-center/start-stop-lambda-cloudwatch/
import boto3
region = 'ap-northeast-2' # RDS가 존재하는 region
db_instance_identifier = 'WRITE YOUR DB INSTANCE IDENTIFIER' # RDS Instance의 식별자
def lambda_handler(event, context):
ec2 = boto3.client('rds', region_name=region)
ec2.stop_db_instance(DBInstanceIdentifier=db_instance_identifier)
print 'stopped your RDS Instance: ' + str(db_instance_identifier)
設定→権限→ロール名のコピー→編集→タイムアウト10秒の設定
AWS IAM-ポリシーメニュー-ポリシーの作成-JSONの作成-次:タグ-次:レビュー-名前(カスタマイズ)-ポリシーの作成
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"rds:Start*",
"rds:Stop*"
],
"Resource": "*"
}
]
}
「ロール」メニュー-「ロール名の貼り付け」(上図)-クリック-接続ポリシー-検索ポリシー名(カスタマイズ)-チェック-接続ポリシー
AWS CloudWatch-イベントメニュー-ルール-Amazon EventBridge-作成ルール-名前、説明-アレイ定義、スケジュール-Cron入力-ターゲット-lambda関数-選択(作成)-作成
매일
오전12시10분 -> 15시10분 stop, cron(10 15 * * ? *)
오전8시40분 -> 23시40분 start, cron(40 23 * * ? *)
Reference
この問題について(AWS RDSの自動起動/停止), 我々は、より多くの情報をここで見つけました https://velog.io/@sunshine0070/AWS-CloudWatchテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol