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).
• Amazon Systems Manager Change Manager is no longer open to new customers. Existing customers can continue to use the service as normal. For more information, see
Amazon Systems Manager Change Manager availability change.
• The Amazon Systems Manager CloudWatch Dashboard will no longer be available after April 30, 2026. Customers can continue to use Amazon CloudWatch console to view, create, and manage their Amazon CloudWatch dashboards, just as they do today. For more information, see
Amazon CloudWatch Dashboard documentation.
Use CreateOpsItem with an Amazon SDK or CLI
The following code examples show how to use CreateOpsItem.
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 create an OpsItems
The following create-ops-item example uses the /aws/resources key in OperationalData to create an OpsItem with an Amazon DynamoDB related resource.
aws ssm create-ops-item \
--title "EC2 instance disk full" \
--description "Log clean up may have failed which caused the disk to be full" \
--priority 2 \
--source ec2 \
--operational-data '{"/aws/resources":{"Value":"[{\"arn\": \"arn:aws:dynamodb:us-west-2:12345678:table/OpsItems\"}]","Type":"SearchableString"}}' \
--notifications Arn="arn:aws:sns:us-west-2:12345678:TestUser"
Output:
{
"OpsItemId": "oi-1a2b3c4d5e6f"
}
For more information, see Creating OpsItems in the Amazon Systems Manager User Guide.
- Java
-
- SDK for Java 2.x
-
/**
* Creates an SSM OpsItem asynchronously.
*
* @param title The title of the OpsItem.
* @param source The source of the OpsItem.
* @param category The category of the OpsItem.
* @param severity The severity of the OpsItem.
* @return The ID of the created OpsItem.
* <p>
* This method initiates an asynchronous request to create an SSM OpsItem.
* If the request is successful, it returns the OpsItem ID.
* If an exception occurs, it handles the error appropriately.
*/
public String createSSMOpsItem(String title, String source, String category, String severity) {
CreateOpsItemRequest opsItemRequest = CreateOpsItemRequest.builder()
.description("Created by the SSM Java API")
.title(title)
.source(source)
.category(category)
.severity(severity)
.build();
CompletableFuture<CreateOpsItemResponse> future = getAsyncClient().createOpsItem(opsItemRequest);
try {
CreateOpsItemResponse response = future.join();
return response.opsItemId();
} catch (CompletionException e) {
Throwable cause = e.getCause();
if (cause instanceof SsmException) {
throw (SsmException) cause;
} else {
throw new RuntimeException(cause);
}
}
}
- JavaScript
-
- SDK for JavaScript (v3)
-
import { CreateOpsItemCommand, SSMClient } from "@aws-sdk/client-ssm";
import { parseArgs } from "node:util";
/**
* Create an SSM OpsItem.
* @param {{ title: string, source: string, category?: string, severity?: string }}
*/
export const main = async ({
title,
source,
category = undefined,
severity = undefined,
}) => {
const client = new SSMClient({});
try {
const { opsItemArn, opsItemId } = await client.send(
new CreateOpsItemCommand({
Title: title,
Source: source, // The origin of the OpsItem, such as Amazon EC2 or Systems Manager.
Category: category,
Severity: severity,
}),
);
console.log(`Ops item created with id: ${opsItemId}`);
return { OpsItemArn: opsItemArn, OpsItemId: opsItemId };
} catch (caught) {
if (caught instanceof Error && caught.name === "MissingParameter") {
console.warn(`${caught.message}. Did you provide these values?`);
} else {
throw caught;
}
}
};
- 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 create(self, title, source, category, severity, description):
"""
Create an OpsItem
:param title: The OpsItem title.
:param source: The OpsItem source.
:param category: The OpsItem category.
:param severity: The OpsItem severity.
:param description: The OpsItem description.
"""
try:
response = self.ssm_client.create_ops_item(
Title=title,
Source=source,
Category=category,
Severity=severity,
Description=description,
)
self.id = response["OpsItemId"]
except self.ssm_client.exceptions.OpsItemLimitExceededException as err:
logger.error(
"Couldn't create ops item because you have exceeded your open OpsItem limit. "
"Here's why: %s: %s",
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
except ClientError as err:
logger.error(
"Couldn't create ops item %s. Here's why: %s: %s",
title,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
- SAP ABAP
-
- SDK for SAP ABAP
-
TRY.
oo_result = lo_ssm->createopsitem(
iv_title = iv_title
iv_source = iv_source
iv_category = iv_category
iv_severity = iv_severity
iv_description = iv_description ).
MESSAGE 'OpsItem created.' TYPE 'I'.
CATCH /aws1/cx_ssmopsitemlimitexcdex.
MESSAGE 'You have exceeded your open OpsItem limit.' TYPE 'I'.
CATCH /aws1/cx_ssmopsitemalrdyexex.
MESSAGE 'OpsItem already exists.' TYPE 'I'.
ENDTRY.
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.