4
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS RDSのAurora ClusterをSystems Manager Automationで定期的に停止させる

Last updated at Posted at 2019-09-17

Clusterを停止するAutomation Documentがない

多分今後作られると思いますがなぜか AWS-StopRdsInstanceはあるのに AWS-StopRdsCluster がありません。
となると CloudWatchの Ruleから定期的に Cron Jobで停止することもできません。 AWS-StopRdsInstanceを参考に作成します。

すぐに結論

AWS-StopRdsInstanceを参考に下記のようなDocumentを作成しました。
結論から言うとAWS-StopRdsInstance の Instance を Clusterに置換、
状態判断の JSONの PropertySelector を DBInstanceStatus ではなく Status にするだけで適用可能です。

---
description: Stop RDS instance
schemaVersion: "0.3"
assumeRole: "{{ AutomationAssumeRole }}"
parameters:
  ClusterId:
    type: String
    description: (Required) RDS Cluster Id to stop
  AutomationAssumeRole:
    type: String
    description: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf.
    default: ""
mainSteps:
  -
    name: AssertNotStopped
    action: aws:assertAwsResourceProperty
    isCritical: false
    onFailure: step:StopCluster
    nextStep: CheckStop
    inputs:
      Service: rds
      Api: DescribeDBClusters
      DBClusterIdentifier: "{{ClusterId}}"
      PropertySelector: "$.DBClusters[0].Status"
      DesiredValues: ["stopped", "stopping"]
  -
    name: StopCluster
    action: aws:executeAwsApi
    inputs:
      Service: rds
      Api: StopDBCluster
      DBClusterIdentifier: "{{ClusterId}}"
  -
    name: CheckStop
    action: aws:waitForAwsResourceProperty
    onFailure: Abort
    maxAttempts: 10
    timeoutSeconds: 600
    inputs:
      Service: rds
      Api: DescribeDBClusters
      DBClusterIdentifier: "{{ClusterId}}"
      PropertySelector: "$.DBClusters[0].Status"
      DesiredValues: ["stopped"]

結論

これをCloudWatchの Ruleに仕込んで Cronで起動すれば終了です。
その内AWSで提供されるようになるのでは…   
というかなんで作らないのか…

参考資料

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/automation-aws-apis-calling.html
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/automation-actions.html#automation-action-executeAwsApi
https://docs.aws.amazon.com/en_pv/AmazonRDS/latest/APIReference/API_DescribeDBClusters.html
https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_StopDBCluster.html

4
9
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
4
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?