Help us understand the problem. What is going on with this article?

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

はじめに

タグを指定するだけで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 }}"
uzresk
触ったプロダクトのメモです。
https://github.com/uzresk
tis
創業40年超のSIerです。
https://www.tis.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした