Merge pull request #209 feature-NEWDWH2021-1094 into develop

This commit is contained in:
下田雅人 2023-05-22 11:12:54 +09:00
commit 5a92b2c263

View File

@ -0,0 +1,29 @@
import os
import boto3
client = boto3.client('rds')
#環境変数
AUTO_START_TAG_TAGKEY = os.environ['AUTO_START_TAG_TAGKEY']
AUTO_START_ENABLE = os.environ['AUTO_START_ENABLE']
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'])