• AWS Systems ManagerChange Manager tidak lagi terbuka untuk pelanggan baru. Pelanggan yang sudah ada dapat terus menggunakan layanan ini seperti biasa. Untuk informasi selengkapnya, lihat perubahan AWS Systems ManagerChange Manager ketersediaan.
• AWS Systems Manager CloudWatch Dasbor tidak akan lagi tersedia setelah 30 April 2026. Pelanggan dapat terus menggunakan CloudWatch konsol Amazon untuk melihat, membuat, dan mengelola CloudWatch dasbor Amazon mereka, seperti yang mereka lakukan hari ini. Untuk informasi selengkapnya, lihat dokumentasi CloudWatch Dasbor Amazon.
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan CreateOpsItem dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanCreateOpsItem.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- CLI
-
- AWS CLI
-
Untuk membuat OpsItems
create-ops-itemContoh berikut menggunakan kunci /aws/resources OperationalData untuk membuat OpsItem dengan sumber daya terkait Amazon DynamoDB.
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"
}
Untuk informasi selengkapnya, lihat Membuat OpsItems di Panduan Pengguna AWS Systems Manager.
- Java
-
- SDK untuk Java 2.x
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
/**
* 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 untuk JavaScript (v3)
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
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 untuk Python (Boto3)
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
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
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
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.
Untuk daftar lengkap panduan pengembang AWS SDK dan contoh kode, lihatMenggunakan layanan ini dengan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.