DescribeSeverityLevels 搭配 AWS SDK或 使用 CLI - AWS Support

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

DescribeSeverityLevels 搭配 AWS SDK或 使用 CLI

下列程式碼範例示範如何使用 DescribeSeverityLevels

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <summary> /// Get the descriptions of support severity levels. /// </summary> /// <param name="name">Optional language for severity levels. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of support severity levels.</returns> public async Task<List<SeverityLevel>> DescribeSeverityLevels(string language = "en") { var response = await _amazonSupport.DescribeSeverityLevelsAsync( new DescribeSeverityLevelsRequest() { Language = language }); return response.SeverityLevels; }
CLI
AWS CLI

列出可用的嚴重性層級

下列describe-severity-levels範例列出支援案例的可用嚴重性等級。

aws support describe-severity-levels

輸出:

{ "severityLevels": [ { "code": "low", "name": "Low" }, { "code": "normal", "name": "Normal" }, { "code": "high", "name": "High" }, { "code": "urgent", "name": "Urgent" }, { "code": "critical", "name": "Critical" } ] }

如需詳細資訊,請參閱 AWS 支援使用者指南 中的選擇嚴重性

Java
SDK 適用於 Java 2.x
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static String displaySevLevels(SupportClient supportClient) { try { DescribeSeverityLevelsRequest severityLevelsRequest = DescribeSeverityLevelsRequest.builder() .language("en") .build(); DescribeSeverityLevelsResponse response = supportClient.describeSeverityLevels(severityLevelsRequest); List<SeverityLevel> severityLevels = response.severityLevels(); String levelName = null; for (SeverityLevel sevLevel : severityLevels) { System.out.println("The severity level name is: " + sevLevel.name()); if (sevLevel.name().compareTo("High") == 0) levelName = sevLevel.name(); } return levelName; } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
JavaScript
SDK 適用於 JavaScript (v3)
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import { DescribeSeverityLevelsCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Get the list of severity levels. // The available values depend on the support plan for the account. const response = await client.send(new DescribeSeverityLevelsCommand({})); console.log(response.severityLevels); return response; } catch (err) { console.error(err); } };
Kotlin
SDK 適用於 Kotlin
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun displaySevLevels(): String { var levelName = "" val severityLevelsRequest = DescribeSeverityLevelsRequest { language = "en" } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.describeSeverityLevels(severityLevelsRequest) response.severityLevels?.forEach { sevLevel -> println("The severity level name is: ${sevLevel.name}") if (sevLevel.name == "High") { levelName = sevLevel.name!! } } return levelName } }
PowerShell
適用於 的工具 PowerShell

範例 1:傳回可指派給 AWS 支援案例的嚴重性層級清單。

Get-ASASeverityLevel

範例 2:傳回可指派給 AWS 支援案例的嚴重性層級清單。層級的名稱會以日文傳回。

Get-ASASeverityLevel -Language "ja"
Python
SDK for Python (Boto3)
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

class SupportWrapper: """Encapsulates Support actions.""" def __init__(self, support_client): """ :param support_client: A Boto3 Support client. """ self.support_client = support_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ support_client = boto3.client("support") return cls(support_client) def describe_severity_levels(self, language): """ Get the descriptions of available severity levels for support cases for a language. :param language: The language for support severity levels. Currently, only "en" (English) and "ja" (Japanese) are supported. :return: The list of severity levels. """ try: response = self.support_client.describe_severity_levels(language=language) severity_levels = response["severityLevels"] except ClientError as err: if err.response["Error"]["Code"] == "SubscriptionRequiredException": logger.info( "You must have a Business, Enterprise On-Ramp, or Enterprise Support " "plan to use the AWS Support API. \n\tPlease upgrade your subscription to run these " "examples." ) else: logger.error( "Couldn't get severity levels for language %s. Here's why: %s: %s", language, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return severity_levels
  • 如需API詳細資訊,請參閱 DescribeSeverityLevels 中的 AWS SDK for Python (Boto3) API參考

如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭 AWS Support 配 AWS SDK 使用。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。