CreateOpsItemOR와 함께 사용 AWS SDK CLI - AWS SDK코드 예제

AWS 문서 AWS SDK SDK 예제 GitHub 리포지토리에 더 많은 예제가 있습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

CreateOpsItemOR와 함께 사용 AWS SDK CLI

다음 코드 예제는 CreateOpsItem의 사용 방법을 보여 줍니다.

작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.

CLI
AWS CLI

만들려면 OpsItems

다음 create-ops-item 예제에서는 /aws/resources 키를 사용하여 Amazon DynamoDB 관련 리소스를 포함하는 인스턴스를 OpsItem 생성합니다. OperationalData

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"

출력:

{ "OpsItemId": "oi-1a2b3c4d5e6f" }

자세한 내용은 AWS Systems Manager 사용 OpsItems 설명서에서 작성을 참조하십시오.

  • 자세한 API 내용은 AWS CLI 명령 CreateOpsItem참조를 참조하십시오.

Java
SDK자바 2.x의 경우
참고

더 많은 내용이 있습니다. GitHub 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); } } }
Python
SDK파이썬용 (보토3)
참고

더 많은 정보가 있습니다. GitHub 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
  • 자세한 API AWS SDK내용은 Python (Boto3) API 참조를 참조하십시오 CreateOpsItem.