• Change Manager de AWS Systems Manager ya no está abierto a nuevos clientes. Los clientes existentes pueden seguir utilizando el servicio con normalidad. Para obtener más información, consulte Cambio en la disponibilidad de Change Manager de AWS Systems Manager.
• El panel de AWS Systems Manager CloudWatch dejará de estar disponible después del 30 de abril de 2026. Los clientes pueden seguir utilizando la consola de Amazon CloudWatch para ver, crear y administrar sus paneles de Amazon CloudWatch, tal y como lo hacen actualmente. Para obtener más información, consulte la documentación del panel de Amazon CloudWatch.
Uso de UpdateOpsItem con un AWS SDK o la CLI
Los siguientes ejemplos de código muestran cómo utilizar UpdateOpsItem.
Los ejemplos de acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Puede ver esta acción en contexto en el siguiente ejemplo de código:
- CLI
-
- AWS CLI
-
Cómo actualizar un OpsItem
En el siguiente ejemplo de update-ops-item se actualizan la descripción, la prioridad y la categoría de un OpsItem. Además, el comando especifica un tema de SNS al que se envían las notificaciones cuando se edita o cambia este OpsItem.
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"
Salida:
This command produces no output.
Para obtener más información, consulte Trabajo con OpsItems en la AWSGuía del usuario de Systems Manager.
- Java
-
- SDK para Java 2.x
-
/**
* 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;
}
}
- JavaScript
-
- SDK para JavaScript (v3)
-
import { UpdateOpsItemCommand, SSMClient } from "@aws-sdk/client-ssm";
import { parseArgs } from "node:util";
/**
* Update an SSM OpsItem.
* @param {{ opsItemId: string, status?: OpsItemStatus }}
*/
export const main = async ({
opsItemId,
status = undefined, // The OpsItem status. Status can be Open, In Progress, or Resolved
}) => {
const client = new SSMClient({});
try {
await client.send(
new UpdateOpsItemCommand({
OpsItemId: opsItemId,
Status: status,
}),
);
console.log("Ops item updated.");
return { Success: true };
} catch (caught) {
if (
caught instanceof Error &&
caught.name === "OpsItemLimitExceededException"
) {
console.warn(
`Couldn't create ops item because you have exceeded your open OpsItem limit. ${caught.message}.`,
);
} else {
throw caught;
}
}
};
- Python
-
- SDK para 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
- SAP ABAP
-
- SDK para SAP ABAP
-
TRY.
lo_ssm->updateopsitem(
iv_opsitemid = iv_ops_item_id
iv_title = iv_title
iv_description = iv_description
iv_status = iv_status ).
MESSAGE 'OpsItem updated.' TYPE 'I'.
CATCH /aws1/cx_ssmopsitemnotfoundex.
MESSAGE 'OpsItem not found.' TYPE 'I'.
CATCH /aws1/cx_ssmopsiteminvparamex.
MESSAGE 'Invalid OpsItem parameter.' TYPE 'I'.
ENDTRY.
Para obtener una lista completa de las guías para desarrolladores de AWS SDK y ejemplos de código, consulte Cómo utilizar este servicio con un AWS SDK. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.