Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use UpdateOpsItem
with an Amazon SDK or CLI
The following code examples show how to use UpdateOpsItem
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- CLI
-
- Amazon CLI
-
To update an OpsItem
The following update-ops-item
example updates the description, priority, and category for an OpsItem. In addition, the command specifies an SNS topic where the notifications are sent when this OpsItem is edited or changed.
aws ssm update-ops-item \
--ops-item-id "oi-287b5EXAMPLE"
\
--description "Primary OpsItem for failover event 2020-01-01-fh398yf"
\
--priority 2
\
--category "Security"
\
--notifications "Arn=arn:aws:sns:us-east-2:111222333444:my-us-east-2-topic"
Output:
This command produces no output.
For more information, see Working with OpsItems in the Amazon Systems Manager User Guide.
- Java
-
- SDK for Java 2.x
-
public static void resolveOpsItem(SsmClient ssmClient, String opsID) {
try {
UpdateOpsItemRequest opsItemRequest = UpdateOpsItemRequest.builder()
.opsItemId(opsID)
.status(OpsItemStatus.RESOLVED)
.build();
ssmClient.updateOpsItem(opsItemRequest);
} catch (SsmException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
- Python
-
- SDK for Python (Boto3)
-
class OpsItemWrapper:
"""Encapsulates AWS Systems Manager OpsItem actions."""
def __init__(self, ssm_client):
"""
:param ssm_client: A Boto3 Systems Manager client.
"""
self.ssm_client = ssm_client
self.id = None
@classmethod
def from_client(cls):
"""
:return: A OpsItemWrapper instance.
"""
ssm_client = boto3.client("ssm")
return cls(ssm_client)
def update(self, title=None, description=None, status=None):
"""
Update an OpsItem.
:param title: The new OpsItem title.
:param description: The new OpsItem description.
:param status: The new OpsItem status.
:return:
"""
args = dict(OpsItemId=self.id)
if title is not None:
args["Title"] = title
if description is not None:
args["Description"] = description
if status is not None:
args["Status"] = status
try:
self.ssm_client.update_ops_item(**args)
except ClientError as err:
logger.error(
"Couldn't update ops item %s. Here's why: %s: %s",
self.id,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
For a complete list of Amazon SDK developer guides and code examples, see
Using Systems Manager with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.