Monitoring Systems Manager status changes using Amazon SNS notifications
You can configure Amazon Simple Notification Service (Amazon SNS) to send notifications about the status of commands that you send using Run Command or Maintenance Windows, which are capabilities of AWS Systems Manager. Amazon SNS coordinates and manages sending and delivering notifications to clients or endpoints that are subscribed to Amazon SNS topics. You can receive a notification whenever a command changes to a new state or to a specific state, such as Failed or Timed Out. In cases where you send a command to multiple nodes, you can receive a notification for each copy of the command sent to a specific node. Each copy is called an invocation.
Amazon SNS can deliver notifications as HTTP or HTTPS POST, email (SMTP, either plaintext or in JSON format), or as a message posted to an Amazon Simple Queue Service (Amazon SQS) queue. For more information, see What is Amazon SNS in the Amazon Simple Notification Service Developer Guide. For examples of the structure of the JSON data included in the Amazon SNS notification provided by Run Command and Maintenance Windows, see Example Amazon SNS notifications for AWS Systems Manager.
Configure Amazon SNS notifications for AWS Systems Manager
Run Command and Maintenance Windows tasks that are registered to a maintenance window can send Amazon SNS notifications for command tasks that enter the following statuses:
-
In Progress
-
Success
-
Failed
-
Timed Out
-
Canceled
For information about the conditions that cause a command to enter one of these statuses, see Understanding command statuses.
Commands sent using Run Command also report Canceling and Pending status. These statuses aren't captured by Amazon SNS notifications.
Command summary Amazon SNS notifications
If you configure Run Command or a Run Command task in your maintenance window for Amazon SNS notifications, Amazon SNS sends summary messages that include the following information.
Field | Type | Description |
---|---|---|
eventTime |
String |
The time that the event was initiated. The timestamp is important because Amazon SNS doesn't guarantee message delivery order. Example: 2016-04-26T13:15:30Z |
documentName |
String |
The name of the SSM document used to run this command. |
commandId |
String |
The ID generated by Run Command after the command was sent. |
expiresAfter |
Date |
If this time is reached and the command hasn't already started executing, it won't run. |
outputS3BucketName |
String |
The Amazon Simple Storage Service (Amazon S3) bucket where the responses to the command execution should be stored. |
outputS3KeyPrefix |
String |
The Amazon S3 directory path inside the bucket where the responses to the command execution should be stored. |
requestedDateTime |
String |
The time and date that the request was sent to this specific node. |
instanceIds |
StringList |
The nodes that were targeted by the command. Instance IDs are only included in the summary message if the Run Command task targeted instance IDs directly. Instance IDs aren't included in the summary message if the Run Command task was issued using tag-based targeting. |
status |
String |
Command status for the command. |
Invocation-based Amazon SNS notifications
If you send a command to multiple nodes, Amazon SNS can send messages about each copy or invocation of the command. The messages include the following information.
Field | Type | Description |
---|---|---|
eventTime |
String |
The time that the event was initiated. The timestamp is important because Amazon SNS doesn't guarantee message delivery order. Example: 2016-04-26T13:15:30Z |
documentName |
String |
The name of the Systems Manager document (SSM document) used to run this command. |
requestedDateTime |
String |
The time and date that the request was sent to this specific node. |
commandId |
String |
The ID generated by Run Command after the command was sent. |
instanceId |
String |
The instance that was targeted by the command. |
status |
String |
Command status for this invocation. |
To set up Amazon SNS notifications when a command changes status, complete the following tasks.
If you aren't configuring Amazon SNS notifications for your maintenance window, then you can skip Task 5 later in this topic.
Topics
Task 1: Create and subscribe to an Amazon SNS topic
An Amazon SNS topic is a communication channel that Run Command and Run Command tasks that are registered to a maintenance window use to send notifications about the status of your commands. Amazon SNS supports different communication protocols, including HTTP/S, email, and other AWS services like Amazon Simple Queue Service (Amazon SQS). To get started, we recommend that you start with the email protocol. For information about how to create a topic, see Creating an Amazon SNS topic in the Amazon Simple Notification Service Developer Guide.
After you create the topic, copy or make a note of the Topic ARN. You specify this ARN when you send a command that is configured to return status notifications.
After you create the topic, subscribe to it by specifying an Endpoint. If you chose the Email protocol, the endpoint is the email address where you want to receive notifications. For more information about how to subscribe to a topic, see Subscribing to an Amazon SNS topic in the Amazon Simple Notification Service Developer Guide.
Amazon SNS sends a confirmation email from AWS Notifications to the email address that you specify. Open the email and choose the Confirm subscription link.
You will receive an acknowledgement message from AWS. Amazon SNS is now configured to receive notifications and send the notification as an email to the email address that you specified.
Task 2: Create an IAM policy for Amazon SNS notifications
Use the following procedure to create a custom AWS Identity and Access Management (IAM) policy that provides permissions for inititating Amazon SNS notifications.
To create a custom IAM policy for Amazon SNS notifications
Open the IAM console at https://console.aws.amazon.com/iam/
. -
In the navigation pane, choose Policies, and then choose Create Policy. (If a Get Started button is shown, choose it, and then choose Create Policy.)
-
Choose the JSON tab.
-
Replace the default content with the following.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": "
arn:aws:sns:
" } ] }region
:account-id
:sns-topic-name
In the following command, replace
region
with your own information. For a list of supportedregion
values, see the Region column in Systems Manager service endpoints in the Amazon Web Services General Reference.
represents the 12-digit identifier for your AWS account, in the formataccount-id
123456789012
.sns-topic-name
represents the name of the Amazon SNS topic you want to use for publishing notifications. -
Choose Next: Tags.
-
(Optional) Add one or more tag-key value pairs to organize, track, or control access for this policy.
-
Choose Next: Review.
-
On the Review policy page, for Name, enter a name for the inline policy. For example:
my-sns-publish-permissions
. -
(Optional) For Description, enter a description for the policy.
-
Choose Create policy.
Task 3: Create an IAM role for Amazon SNS notifications
Use the following procedure to create an IAM role for Amazon SNS notifications. This service role is used by Systems Manager to initiate Amazon SNS notifications. In all subsequent procedures, this role is referred to as the Amazon SNS IAM role.
To create an IAM service role for Amazon SNS notifications
Open the IAM console at https://console.aws.amazon.com/iam/
. -
In the navigation pane, choose Roles, and then choose Create role.
-
Under Select type of trusted entity, choose AWS service.
-
In the Choose a use case section, choose Systems Manager.
-
In the Select your use case section, choose Systems Manager, and then choose Next: Permissions.
-
On the Attach permissions policies page, select the box to the left of the name of the custom policy you created in Task 2. For example:
my-sns-publish-permissions
. -
Choose Next: Tags.
-
(Optional) Add one or more tag-key value pairs to organize, track, or control access for this role.
-
Choose Next: Review.
-
On the Review page, for Role name, enter a name to identify the role, such as
my-sns-role
. -
(Optional) Change the default role description to reflect the purpose of this role. For example:
Runs SNS topics on your behalf.
-
Choose Create role. The system returns you to the Roles page.
-
Choose the name of the role, and then copy or make a note of the Role ARN value. This Amazon Resource Name (ARN) for the role is used when you send a command that is configured to return Amazon SNS notifications.
-
Keep the Summary page open.
Task 4: Configure user access
If your IAM user account, group, or role is assigned administrator
permissions, then you have access to Run Command and Maintenance Windows, capabilities of
AWS Systems Manager. If you don't have administrator permissions, then an administrator
must give you permission by assigning the AmazonSSMFullAccess
managed policy, or a policy that provides comparable permissions, to your IAM
account, group, or role.
Use the following procedure to configure a user account to use Run Command and Maintenance Windows. If you need to create a new user account, see Creating an IAM user in your AWS account in the IAM User Guide.
To configure user access and attach the iam:PassRole
policy
to a user account
-
In the IAM navigation pane, choose Users, and then choose the user account that you want to configure.
-
On the Permissions tab, in the policies list, verify that either the
AmazonSSMFullAccess
policy is listed or that there is a comparable policy that gives the account permissions to access Systems Manager. -
Choose Add inline policy.
-
On the Create policy page, choose the Visual editor tab.
-
Choose Choose a service, and then choose IAM.
-
For Actions, in the Filter actions text box, enter
PassRole
, and then select the check box next to PassRole. -
For Resources, verify that Specific is selected, and then choose Add ARN.
-
In the Specify ARN for role field, paste the Amazon SNS IAM role ARN that you copied at the end of Task 3. The system automatically populates the Account and Role name with path fields.
-
Choose Add.
-
Choose Review policy.
-
On the Review Policy page, enter a name and then choose Create policy.
Task 5: Attach the iam:PassRole policy to your maintenance window role
When you register a Run Command task with a maintenance window, you specify a
service role Amazon Resource Name (ARN). This service role is used by Systems Manager to
run tasks registered to the maintenance window. To configure Amazon SNS notifications
for a registered Run Command task, attach an iam:PassRole
policy to
the maintenance window service role specified. If you don't intend to configure
the registered task for Amazon SNS notifications, then you can skip this task.
The iam:PassRole
policy allows the Maintenance Windows service role to pass
the Amazon SNS IAM role created in Task 3 to the Amazon SNS service. The following
procedure shows how to attach the iam:PassRole
policy to the
Maintenance Windows service role.
Use a custom service role for your maintenance window to send notifications related to the Run Command tasks registered. For information, see Should I use a service-linked role or a custom service role to run maintenance window tasks?.
If you need to create a custom service role, see one of the following topics:
To attach the iam:PassRole
policy to your Maintenance Windows
role
-
Open the IAM console at https://console.aws.amazon.com/iam/
. -
In the navigation pane, choose Roles and select the Amazon SNS IAM role created in Task 3.
-
Copy or make a note of the Role ARN and return to the Roles section of the IAM console.
-
Select the custom Maintenance Windows service role you created from the Role name list.
-
On the Permissions tab, verify that either the
AmazonSSMMaintenanceWindowRole
policy is listed or there is a comparable policy that gives maintenance windows permission to the Systems Manager API. If it is not, choose Attach policies to attach it. -
Choose Add inline policy.
-
Choose the Visual editor tab.
-
For Service, choose IAM.
-
For Actions, in the Filter actions text box, enter
PassRole
, and then select the check box next to PassRole. -
For Resources, choose Specific, and then choose Add ARN.
-
In the Specify ARN for role box, paste the ARN of the Amazon SNS IAM role created in Task 3, and then choose Add.
-
Choose Review policy.
-
On the Review Policy page, specify a name for the
PassRole
policy, and then choose Create policy.