feat: 自動開始スクリプトを追加
This commit is contained in:
parent
be64e2f0ac
commit
c46b4ad552
29
lambda/start-rds/start-rds.py
Normal file
29
lambda/start-rds/start-rds.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
import boto3
|
||||
|
||||
#環境変数
|
||||
client = boto3.client('rds')
|
||||
|
||||
AUTO_START_TAG_TAGKEY = 'AUTO_START'
|
||||
AUTO_START_ENABLE = 'true'
|
||||
|
||||
def lambda_handler(event, context):
|
||||
#クラスターを停止
|
||||
clusters = client.describe_db_clusters()
|
||||
for cluster in clusters['DBClusters']:
|
||||
if cluster['Status'] == "stopped":
|
||||
tags = client.list_tags_for_resource(ResourceName=cluster['DBClusterArn'])
|
||||
for tag in tags['TagList']:
|
||||
if tag['Key'] == AUTO_START_TAG_TAGKEY and tag['Value'] == AUTO_START_ENABLE:
|
||||
client.start_db_cluster(DBClusterIdentifier=cluster['DBClusterIdentifier'])
|
||||
|
||||
#インスタンスを停止
|
||||
instances = client.describe_db_instances()
|
||||
for instance in instances['DBInstances']:
|
||||
if instance['DBInstanceStatus'] == "stopped":
|
||||
tags = client.list_tags_for_resource(ResourceName=instance['DBInstanceArn'])
|
||||
for tag in tags['TagList']:
|
||||
if tag['Key'] == AUTO_START_TAG_TAGKEY and tag['Value'] == AUTO_START_ENABLE:
|
||||
client.start_db_instance(DBInstanceIdentifier=instance['DBInstanceIdentifier'])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user