LoginSignup
8
6

More than 3 years have passed since last update.

タグを指定するだけでRDSを自動起動・停止する

Posted at

はじめに

タグを指定するだけでEC2インスタンスを自動起動・停止する」のRDS版です。

案件で必要になったためメモを残しておきます。

やりたいこと

RDSタグにStartTime:8am、StopTime:9pmを設定すると朝8時に自動起動、夜9時に自動停止させます。

手順は前回と全く同じなのでドキュメントのコンテンツだけの記事です。

注意点

タグに対応するDB識別子が取得できない場合、SSMAutomationは失敗します。
つまりCloudWatchRulesに7amに起動するルールを設定したとしてもRDSにStartTime:7amに対応するルールがないと失敗してしまうのでその点だけご注意ください。

RDSの自動起動

description: StartRdsInstances Using Tags:StartTime
schemaVersion: "0.3"
assumeRole: "{{ AutomationAssumeRole }}"
parameters:
  StartTime:
    type: String
    default: 8am
    description: (Required) 7am,8am,9am
    allowedValues:
    - 7am
    - 8am
    - 9am
  AutomationAssumeRole:
    type: String
    description: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf.
    default: ""
mainSteps:
  - name: StartRdsInstance
    action: aws:executeAwsApi
    inputs:
      Service: ssm
      Api: StartAutomationExecution
      DocumentName: AWS-StartRdsInstance
      TargetParameterName: "InstanceId"
      Targets:
        -
           Key: tag:StartTime
           Values: 
             - "{{ StartTime }}"

RDSの自動停止

description: StopRdsInstances Using Tags:StopTime
schemaVersion: "0.3"
assumeRole: "{{ AutomationAssumeRole }}"
parameters:
  StopTime:
    type: String
    default: 8pm
    description: (Required) 8pm,9pm,10pm,11pm
    allowedValues:
    - 8pm
    - 9pm
    - 10pm
    - 11pm
  AutomationAssumeRole:
    type: String
    description: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf.
    default: ""
mainSteps:
  - name: StopRdsInstance
    action: aws:executeAwsApi
    inputs:
      Service: ssm
      Api: StartAutomationExecution
      DocumentName: AWS-StopRdsInstance
      TargetParameterName: "InstanceId"
      Targets:
        -
           Key: tag:StopTime
           Values: 
             - "{{ StopTime }}"
8
6
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
8
6