AWS Health 使用 的範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS Health 使用 的範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 來執行動作和實作常見案例 AWS Health。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 describe-affected-entities

AWS CLI

列出受指定 AWS 運作狀態事件影響的實體

下列describe-affected-entities範例列出受指定 AWS 運作狀態事件影響的實體。此事件是 AWS 帳戶的帳單通知。

aws health describe-affected-entities \ --filter "eventArns=arn:aws:health:global::event/BILLING/AWS_BILLING_NOTIFICATION/AWS_BILLING_NOTIFICATION_6ce1d874-e995-40e2-99cd-EXAMPLE11145" \ --region us-east-1

輸出:

{ "entities": [ { "entityArn": "arn:aws:health:global:123456789012:entity/EXAMPLEimSMoULmWHpb", "eventArn": "arn:aws:health:global::event/BILLING/AWS_BILLING_NOTIFICATION/AWS_BILLING_NOTIFICATION_6ce1d874-e995-40e2-99cd-EXAMPLE11145", "entityValue": "AWS_ACCOUNT", "awsAccountId": "123456789012", "lastUpdatedTime": 1588356454.08 } ] }

如需詳細資訊,請參閱AWS 運作狀態使用者指南中的事件日誌

下列程式碼範例示範如何使用 describe-event-details

AWS CLI

若要列出 AWS 運作狀態事件的相關資訊

下列describe-event-details範例會列出指定 AWS 運作狀態事件的相關資訊。

aws health describe-event-details \ --event-arns "arn:aws:health:us-east-1::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_VKTXI_EXAMPLE111" \ --region us-east-1

輸出:

{ "successfulSet": [ { "event": { "arn": "arn:aws:health:us-east-1::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_VKTXI_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-east-1", "startTime": 1587462325.096, "endTime": 1587464204.774, "lastUpdatedTime": 1587464204.865, "statusCode": "closed" }, "eventDescription": { "latestDescription": "[RESOLVED] Increased API Error Rates and Latencies\n\n[02:45 AM PDT] We are investigating increased API error rates and latencies in the US-EAST-1 Region.\n\n[03:16 AM PDT] Between 2:10 AM and 2:59 AM PDT we experienced increased API error rates and latencies in the US-EAST-1 Region. The issue has been resolved and the service is operating normally." } } ], "failedSet": [] }

如需詳細資訊,請參閱AWS 運作狀態使用者指南中的事件詳細資訊窗格

下列程式碼範例示範如何使用 describe-events

AWS CLI

範例 1:列出 AWS 運作狀態事件

下列describe-events範例列出最近的 AWS 運作狀態事件。

aws health describe-events \ --region us-east-1

輸出:

{ "events": [ { "arn": "arn:aws:health:us-west-1::event/ECS/AWS_ECS_OPERATIONAL_ISSUE/AWS_ECS_OPERATIONAL_ISSUE_KWQPY_EXAMPLE111", "service": "ECS", "eventTypeCode": "AWS_ECS_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-west-1", "startTime": 1589077890.53, "endTime": 1589086345.597, "lastUpdatedTime": 1589086345.905, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:global::event/BILLING/AWS_BILLING_NOTIFICATION/AWS_BILLING_NOTIFICATION_6ce1d874-e995-40e2-99cd-EXAMPLE1118b", "service": "BILLING", "eventTypeCode": "AWS_BILLING_NOTIFICATION", "eventTypeCategory": "accountNotification", "region": "global", "startTime": 1588356000.0, "lastUpdatedTime": 1588356524.358, "statusCode": "open", "eventScopeCode": "ACCOUNT_SPECIFIC" }, { "arn": "arn:aws:health:us-west-2::event/CLOUDFORMATION/AWS_CLOUDFORMATION_OPERATIONAL_ISSUE/AWS_CLOUDFORMATION_OPERATIONAL_ISSUE_OHTWY_EXAMPLE111", "service": "CLOUDFORMATION", "eventTypeCode": "AWS_CLOUDFORMATION_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-west-2", "startTime": 1588279630.761, "endTime": 1588284650.0, "lastUpdatedTime": 1588284691.941, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:ap-northeast-1::event/LAMBDA/AWS_LAMBDA_OPERATIONAL_ISSUE/AWS_LAMBDA_OPERATIONAL_ISSUE_JZDND_EXAMPLE111", "service": "LAMBDA", "eventTypeCode": "AWS_LAMBDA_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "ap-northeast-1", "startTime": 1587379534.08, "endTime": 1587391771.0, "lastUpdatedTime": 1587395689.316, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:us-east-1::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_COBXJ_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-east-1", "startTime": 1586473044.284, "endTime": 1586479706.091, "lastUpdatedTime": 1586479706.153, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:global::event/SECURITY/AWS_SECURITY_NOTIFICATION/AWS_SECURITY_NOTIFICATION_42007387-8129-42da-8c88-EXAMPLE11139", "service": "SECURITY", "eventTypeCode": "AWS_SECURITY_NOTIFICATION", "eventTypeCategory": "accountNotification", "region": "global", "startTime": 1585674000.0, "lastUpdatedTime": 1585674004.132, "statusCode": "open", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:global::event/CLOUDFRONT/AWS_CLOUDFRONT_OPERATIONAL_ISSUE/AWS_CLOUDFRONT_OPERATIONAL_ISSUE_FRQXG_EXAMPLE111", "service": "CLOUDFRONT", "eventTypeCode": "AWS_CLOUDFRONT_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "global", "startTime": 1585610898.589, "endTime": 1585617671.0, "lastUpdatedTime": 1585620638.869, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:us-east-1::event/SES/AWS_SES_OPERATIONAL_ISSUE/AWS_SES_OPERATIONAL_ISSUE_URNDF_EXAMPLE111", "service": "SES", "eventTypeCode": "AWS_SES_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-east-1", "startTime": 1585342008.46, "endTime": 1585344017.0, "lastUpdatedTime": 1585344355.989, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:global::event/IAM/AWS_IAM_OPERATIONAL_NOTIFICATION/AWS_IAM_OPERATIONAL_NOTIFICATION_b6771c34-6ecd-4aea-9d3e-EXAMPLE1117e", "service": "IAM", "eventTypeCode": "AWS_IAM_OPERATIONAL_NOTIFICATION", "eventTypeCategory": "accountNotification", "region": "global", "startTime": 1584978300.0, "lastUpdatedTime": 1584978553.572, "statusCode": "open", "eventScopeCode": "ACCOUNT_SPECIFIC" }, { "arn": "arn:aws:health:ap-southeast-2::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_HNGHE_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "ap-southeast-2", "startTime": 1583881487.483, "endTime": 1583885056.785, "lastUpdatedTime": 1583885057.052, "statusCode": "closed", "eventScopeCode": "PUBLIC" } ] }

如需詳細資訊,請參閱運作狀態使用者指南中的 AWS 個人運作狀態儀表板入門AWS

範例 2:依服務和事件狀態碼列出 AWS 運作狀態事件

下列describe-events範例列出事件狀態已關閉的 Amazon Elastic Compute Cloud (Amazon EC2) AWS 運作狀態事件。

aws health describe-events \ --filter "services=EC2,eventStatusCodes=closed"

輸出:

{ "events": [ { "arn": "arn:aws:health:us-east-1::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_VKTXI_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-east-1", "startTime": 1587462325.096, "endTime": 1587464204.774, "lastUpdatedTime": 1587464204.865, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:us-east-1::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_COBXJ_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "us-east-1", "startTime": 1586473044.284, "endTime": 1586479706.091, "lastUpdatedTime": 1586479706.153, "statusCode": "closed", "eventScopeCode": "PUBLIC" }, { "arn": "arn:aws:health:ap-southeast-2::event/EC2/AWS_EC2_OPERATIONAL_ISSUE/AWS_EC2_OPERATIONAL_ISSUE_HNGHE_EXAMPLE111", "service": "EC2", "eventTypeCode": "AWS_EC2_OPERATIONAL_ISSUE", "eventTypeCategory": "issue", "region": "ap-southeast-2", "startTime": 1583881487.483, "endTime": 1583885056.785, "lastUpdatedTime": 1583885057.052, "statusCode": "closed", "eventScopeCode": "PUBLIC" } ] }

如需詳細資訊,請參閱運作狀態使用者指南中的 AWS 個人運作狀態儀表板入門AWS

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeEvents