AWS Doc SDK ExamplesWord
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
an AWS SDK 또는 CLIDescribeOpsItems
와 함께 사용
다음 코드 예제는 DescribeOpsItems
의 사용 방법을 보여 줍니다.
- CLI
-
- AWS CLI
-
OpsItems 세트를 나열하려면
다음
describe-ops-items
예제에서는 AWS 계정의 모든 open OpsItems 목록을 표시합니다.aws ssm describe-ops-items \ --ops-item-filters
"Key=Status,Values=Open,Operator=Equal"
출력:
{ "OpsItemSummaries": [ { "CreatedBy": "arn:aws:sts::111222333444:assumed-role/OpsItem-CWE-Role/fbf77cbe264a33509569f23e4EXAMPLE", "CreatedTime": "2020-03-14T17:02:46.375000-07:00", "LastModifiedBy": "arn:aws:sts::111222333444:assumed-role/OpsItem-CWE-Role/fbf77cbe264a33509569f23e4EXAMPLE", "LastModifiedTime": "2020-03-14T17:02:46.375000-07:00", "Source": "SSM", "Status": "Open", "OpsItemId": "oi-7cfc5EXAMPLE", "Title": "SSM Maintenance Window execution failed", "OperationalData": { "/aws/dedup": { "Value": "{\"dedupString\":\"SSMOpsItems-SSM-maintenance-window-execution-failed\"}", "Type": "SearchableString" }, "/aws/resources": { "Value": "[{\"arn\":\"arn:aws:ssm:us-east-2:111222333444:maintenancewindow/mw-034093d322EXAMPLE\"}]", "Type": "SearchableString" } }, "Category": "Availability", "Severity": "3" }, { "CreatedBy": "arn:aws:sts::1112223233444:assumed-role/OpsItem-CWE-Role/fbf77cbe264a33509569f23e4EXAMPLE", "CreatedTime": "2020-02-26T11:43:15.426000-08:00", "LastModifiedBy": "arn:aws:sts::111222333444:assumed-role/OpsItem-CWE-Role/fbf77cbe264a33509569f23e4EXAMPLE", "LastModifiedTime": "2020-02-26T11:43:15.426000-08:00", "Source": "EC2", "Status": "Open", "OpsItemId": "oi-6f966EXAMPLE", "Title": "EC2 instance stopped", "OperationalData": { "/aws/automations": { "Value": "[ { \"automationType\": \"AWS:SSM:Automation\", \"automationId\": \"AWS-RestartEC2Instance\" } ]", "Type": "SearchableString" }, "/aws/dedup": { "Value": "{\"dedupString\":\"SSMOpsItems-EC2-instance-stopped\"}", "Type": "SearchableString" }, "/aws/resources": { "Value": "[{\"arn\":\"arn:aws:ec2:us-east-2:111222333444:instance/i-0beccfbc02EXAMPLE\"}]", "Type": "SearchableString" } }, "Category": "Availability", "Severity": "3" } ] }
자세한 내용은 AWS Systems Manager 사용 설명서의 OpsItems 작업을 참조하세요.
-
API 세부 정보는 AWS CLI 명령 참조의 DescribeOpsItems
를 참조하세요.
-
- Java
-
- Java 2.x용 SDK
-
참고
더 많은 on GitHub가 있습니다. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. /** * Describes AWS SSM OpsItems asynchronously. * * @param key The key to filter OpsItems by (e.g., OPS_ITEM_ID). * * This method initiates an asynchronous request to describe SSM OpsItems. * If the request is successful, it prints the title and status of each OpsItem. * If an exception occurs, it handles the error appropriately. */ public void describeOpsItems(String key) { OpsItemFilter filter = OpsItemFilter.builder() .key(OpsItemFilterKey.OPS_ITEM_ID) .values(key) .operator(OpsItemFilterOperator.EQUAL) .build(); DescribeOpsItemsRequest itemsRequest = DescribeOpsItemsRequest.builder() .maxResults(10) .opsItemFilters(filter) .build(); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { getAsyncClient().describeOpsItems(itemsRequest) .thenAccept(itemsResponse -> { List<OpsItemSummary> items = itemsResponse.opsItemSummaries(); for (OpsItemSummary item : items) { System.out.println("The item title is " + item.title() + " and the status is " + item.status().toString()); } }) .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; } }
-
API 세부 정보는 DescribeOpsItems in AWS SDK for Java 2.x API 참조를 참조하세요.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
참고
더 많은 on GitHub가 있습니다. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. import { OpsItemFilterOperator, OpsItemFilterKey, paginateDescribeOpsItems, SSMClient, } from "@aws-sdk/client-ssm"; import { parseArgs } from "node:util"; /** * Describe SSM OpsItems. * @param {{ opsItemId: string }} */ export const main = async ({ opsItemId }) => { const client = new SSMClient({}); try { const describeOpsItemsPaginated = []; for await (const page of paginateDescribeOpsItems( { client }, { OpsItemFilters: { Key: OpsItemFilterKey.OPSITEM_ID, Operator: OpsItemFilterOperator.EQUAL, Values: opsItemId, }, }, )) { describeOpsItemsPaginated.push(...page.OpsItemSummaries); } console.log("Here are the ops items:"); console.log(describeOpsItemsPaginated); return { OpsItemSummaries: describeOpsItemsPaginated }; } catch (caught) { if (caught instanceof Error && caught.name === "MissingParameter") { console.warn(`${caught.message}. Did you provide this value?`); } throw caught; } };
-
API 세부 정보는 DescribeOpsItems AWS SDK for JavaScript 참조의 API를 참조하세요.
-
- Python
-
- Python용 SDK(Boto3)
-
참고
더 많은 on 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 describe(self): """ Describe an OpsItem. """ try: paginator = self.ssm_client.get_paginator("describe_ops_items") ops_items = [] for page in paginator.paginate( OpsItemFilters=[ {"Key": "OpsItemId", "Values": [self.id], "Operator": "Equal"} ] ): ops_items.extend(page["OpsItemSummaries"]) for item in ops_items: print( f"The item title is {item['Title']} and the status is {item['Status']}" ) return len(ops_items) > 0 except ClientError as err: logger.error( "Couldn't describe ops item %s. Here's why: %s: %s", self.id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
-
API 세부 정보는 Word for Python(Boto3) DescribeOpsItems 참조의 Word를 참조하세요. AWS SDK API
-