0
votes

Say I have an SSM document like the below, and I want to be alerted when a run fails or doesn't finish for whatever reason:

{
  "description": "Restores specified pg_dump backup to specified RDS/DB.",
  "mainSteps": [
    {
      "action": "aws:runCommand",
      "description": "Restores specified pg_dump backup to specified RDS/DB.",
      "inputs": {
        "DocumentName": "AWS-RunShellScript",
        "Parameters": {
          "commands": [
            "blahblahblah"
          ],
          "executionTimeout": "1800"
        },
        "Targets": [
          {
            "Key": "InstanceIds",
            "Values": [
              "i-xxxxxxxx"
            ]
          }
        ]
      },
      "name": "DBRestorer",
      "nextStep": "RunQueries"
    },

Terraform documents show me that RunCommand documents should support a NotificationConfig where I can pass in my SNS topic ARN and declare what state transitions should trigger a message: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_maintenance_window_task#notification_config

However, I can't find any Amazon docs that actually include the use of a notification configuration in the document itself (not just the maintenance window, which I have set up as automation so it doesn't support it at the window level), so I'm not sure if it belongs as a sub-parameter, or whether to define it with camel case or dash separation.

1

1 Answers

1
votes

Try this

{
  "description": "Restores specified pg_dump backup to specified RDS/DB.",
  "mainSteps": [
    {
      "action": "aws:runCommand",
      "description": "Restores specified pg_dump backup to specified RDS/DB.",
      "inputs": {
        "DocumentName": "AWS-RunShellScript",
        "NotificationConfig": {
          "NotificationArn": "<<Replace this with a SNS Topic Arn>>",
          "NotificationEvents": ["All"],
          "NotificationType": "Invocation"
        },
        "ServiceRoleArn": "<<Replace this with an IAM role Arn that has access to SNS>>",
        "Parameters": {
          "commands": [
            "blahblahblah"
          ],
          "executionTimeout": "1800"
        },
        "Targets": [
          {
            "Key": "InstanceIds",
            "Values": [
              "i-xxxxxxxx"
            ]
          }
        ]
      },
      "name": "DBRestorer",
      "nextStep": "RunQueries"
    },
    ...
  ]
}

Related documentation: