From c46b4ad552b55d503e883ee2e659dbee9575e6b8 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Fri, 19 May 2023 14:47:14 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=87=AA=E5=8B=95=E9=96=8B?= =?UTF-8?q?=E5=A7=8B=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/start-rds/start-rds.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lambda/start-rds/start-rds.py diff --git a/lambda/start-rds/start-rds.py b/lambda/start-rds/start-rds.py new file mode 100644 index 00000000..a077cb88 --- /dev/null +++ b/lambda/start-rds/start-rds.py @@ -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']) + From 509fb61218c86ea7b507e0d8de4f779cad82c0ee Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Fri, 19 May 2023 14:50:30 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E3=82=BF=E3=82=B0=E5=90=8D=E3=81=A8?= =?UTF-8?q?=E5=80=A4=E3=81=AF=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=8F=96=E3=82=8B=EF=BC=88stop=E3=82=92=E8=B8=8F?= =?UTF-8?q?=E8=A5=B2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/start-rds/start-rds.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambda/start-rds/start-rds.py b/lambda/start-rds/start-rds.py index a077cb88..b35d7650 100644 --- a/lambda/start-rds/start-rds.py +++ b/lambda/start-rds/start-rds.py @@ -5,8 +5,8 @@ import boto3 #環境変数 client = boto3.client('rds') -AUTO_START_TAG_TAGKEY = 'AUTO_START' -AUTO_START_ENABLE = 'true' +AUTO_START_TAG_TAGKEY = os.environ['AUTO_START_TAG_TAGKEY'] +AUTO_START_ENABLE = os.environ['AUTO_START_ENABLE'] def lambda_handler(event, context): #クラスターを停止 From 0e643c21ba9e0a4199841bb0f719939267f4a01a Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Fri, 19 May 2023 14:51:25 +0900 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=8C=E5=98=98=E4=BB=98=E3=81=84=E3=81=A6=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/start-rds/start-rds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/start-rds/start-rds.py b/lambda/start-rds/start-rds.py index b35d7650..ee4f4b9b 100644 --- a/lambda/start-rds/start-rds.py +++ b/lambda/start-rds/start-rds.py @@ -2,9 +2,9 @@ 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']