Gunakan UpdateOpsItem dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan UpdateOpsItem dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanUpdateOpsItem.

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 memperbarui OpsItem

update-ops-itemContoh berikut memperbarui deskripsi, prioritas, dan kategori untuk file OpsItem. Selain itu, perintah menentukan SNS topik di mana pemberitahuan dikirim saat ini OpsItem diedit atau diubah.

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.

Untuk informasi selengkapnya, lihat Bekerja dengan OpsItems di Panduan Pengguna AWS Systems Manager.

  • Untuk API detailnya, lihat UpdateOpsItemdi Referensi AWS CLI Perintah.

Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

/** * Resolves an AWS SSM OpsItem asynchronously. * * @param opsID The ID of the OpsItem to resolve. * <p> * This method initiates an asynchronous request to resolve an SSM OpsItem. * If an exception occurs, it handles the error appropriately. */ public void resolveOpsItem(String opsID) { UpdateOpsItemRequest opsItemRequest = UpdateOpsItemRequest.builder() .opsItemId(opsID) .status(OpsItemStatus.RESOLVED) .build(); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { getAsyncClient().updateOpsItem(opsItemRequest) .thenAccept(response -> { System.out.println("OpsItem resolved successfully."); }) .exceptionally(ex -> { throw new CompletionException(ex); }).join(); }).exceptionally(ex -> { Throwable cause = (ex instanceof CompletionException) ? ex.getCause() : ex; if (cause instanceof SsmException) { throw new RuntimeException("SSM error: " + cause.getMessage(), cause); } else { throw new RuntimeException("Unexpected error: " + cause.getMessage(), cause); } }); try { future.join(); } catch (CompletionException ex) { throw ex.getCause() instanceof RuntimeException ? (RuntimeException) ex.getCause() : ex; } }
  • Untuk API detailnya, lihat UpdateOpsItemdi AWS SDK for Java 2.x APIReferensi.

Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan 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 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