Skip to content

Instantly share code, notes, and snippets.

@faudeltn
Created March 18, 2025 10:00
Show Gist options
  • Select an option

  • Save faudeltn/d279831195e666a17003a48dc1f27fcc to your computer and use it in GitHub Desktop.

Select an option

Save faudeltn/d279831195e666a17003a48dc1f27fcc to your computer and use it in GitHub Desktop.
#
# Copyright 2023 yallalabs.com. All Rights Reserved.
#
---
description: |-
## Id
Document Name: YALLALABS-StopDocdbCluster
Copyright 2023 yallalabs.com. All Rights Reserved.
## What does this document do?
This document stops an Amazon DocumentDB cluster.
## Type
TEST
## Risk
Small
## Requirements
* Available DocumentDB Cluster
## Permissions required for AutomationAssumeRole
* `rds:StopDBCluster` on the targeted cluster.
* `rds:DescribeDBClusters` on all clusters.
## Supports Rollback
No
## Cancellation behavior
Fails
## Inputs
### (Optional) AutomationAssumeRole
* type: String
* description: ARN of the IAM role with permissions listed above
### (Required) DBClusterIdentifier
* type: String
* description: DocumentDB Cluster Identifier
## Details
The document stops DocumentDB cluster and wait for it to become stopped.
## Steps executed in normal flow
* AssertNotStopped
* StopDbCluster
* CheckStop
## Outputs
None
schemaVersion: "0.3"
assumeRole: "{{ AutomationAssumeRole }}"
parameters:
DBClusterIdentifier:
type: String
description: (Required) DocDb Cluster Identifier
AutomationAssumeRole:
type: String
description: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf.
default: ""
allowedPattern: "^arn:aws(-cn|-us-gov)?:iam::\\d{12}:role/[\\w+=,.@/-]+|^$"
mainSteps:
- name: AssertNotStopped
action: aws:assertAwsResourceProperty
isCritical: false
onFailure: step:StopDBCluster
nextStep: CheckStop
inputs:
Service: docdb
Api: DescribeDBInstances
Filters:
- Name: "db-cluster-id"
Values:
- '{{ DBClusterIdentifier }}'
PropertySelector: '$.DBInstances..DBInstanceStatus'
DesiredValues: ["stopped", "stopping"]
- name: StopDBCluster
description: Stop the DocumentDB cluster
action: aws:executeAwsApi
inputs:
Service: docdb
Api: StopDBCluster
DBClusterIdentifier: '{{ DBClusterIdentifier }}'
- name: CheckStop
action: aws:waitForAwsResourceProperty
onFailure: Abort
maxAttempts: 10
timeoutSeconds: 600
inputs:
Service: docdb
Api: DescribeDBInstances
Filters:
- Name: "db-cluster-id"
Values:
- '{{ DBClusterIdentifier }}'
PropertySelector: '$.DBInstances..DBInstanceStatus'
DesiredValues: ["stopped"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment