AWS Support SDK for Python(Boto3)을 사용한 예제 - AWS SDK 코드 예제

AWS Doc SDK ExamplesWord AWS SDK 리포지토리에는 더 많은 GitHub 예제가 있습니다.

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

AWS Support SDK for Python(Boto3)을 사용한 예제

다음 코드 예제에서는를 AWS SDK for Python (Boto3) 와 함께 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다 AWS Support.

기본 사항은 서비스 내에서 필수 작업을 수행하는 방법을 보여주는 코드 예제입니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예제에는 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 전체 소스 코드에 대한 링크가 포함되어 있습니다.

시작

다음 코드 예제에서는 AWS Support의 사용을 시작하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on GitHub가 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def hello_support(support_client): """ Use the AWS SDK for Python (Boto3) to create an AWS Support client and count the available services in your account. This example uses the default settings specified in your shared credentials and config files. :param support_client: A Boto3 Support Client object. """ try: print("Hello, AWS Support! Let's count the available Support services:") response = support_client.describe_services() print(f"There are {len(response['services'])} services available.") 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 count services. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise if __name__ == "__main__": hello_support(boto3.client("support"))
  • API 세부 정보는 Word for Python(Boto3) DescribeServices 참조의 Word를 참조하세요. AWS SDK API

기본 사항

다음 코드 예시는 다음과 같은 작업을 수행하는 방법을 보여줍니다.

  • 사용 가능한 서비스 및 사례의 심각도 수준을 가져와서 표시합니다.

  • 선택한 서비스, 범주 및 심각도 수준을 사용하여 지원 사례를 만듭니다.

  • 현재 일자의 미해결 사례 목록을 가져와서 표시합니다.

  • 새로운 사례에 첨부 파일 세트와 통신을 추가합니다.

  • 해당 사례에 대한 새로운 첨부 파일과 통신을 설명하세요.

  • 사건을 해결하세요.

  • 현재 일자의 해결된 사례 목록을 가져와서 표시합니다.

Python용 SDK(Boto3)
참고

더 많은 on GitHub가 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

명령 프롬프트에서 대화형 시나리오를 실행합니다.

class SupportCasesScenario: """Runs an interactive scenario that shows how to get started using AWS Support.""" def __init__(self, support_wrapper): """ :param support_wrapper: An object that wraps AWS Support actions. """ self.support_wrapper = support_wrapper def display_and_select_service(self): """ Lists support services and prompts the user to select one. :return: The support service selected by the user. """ print("-" * 88) services_list = self.support_wrapper.describe_services("en") print(f"AWS Support client returned {len(services_list)} services.") print("Displaying first 10 services:") service_choices = [svc["name"] for svc in services_list[:10]] selected_index = q.choose( "Select an example support service by entering a number from the preceding list:", service_choices, ) selected_service = services_list[selected_index] print("-" * 88) return selected_service def display_and_select_category(self, service): """ Lists categories for a support service and prompts the user to select one. :param service: The service of the categories. :return: The selected category. """ print("-" * 88) print( f"Available support categories for Service {service['name']} {len(service['categories'])}:" ) categories_choices = [category["name"] for category in service["categories"]] selected_index = q.choose( "Select an example support category by entering a number from the preceding list:", categories_choices, ) selected_category = service["categories"][selected_index] print("-" * 88) return selected_category def display_and_select_severity(self): """ Lists available severity levels and prompts the user to select one. :return: The selected severity level. """ print("-" * 88) severity_levels_list = self.support_wrapper.describe_severity_levels("en") print(f"Available severity levels:") severity_choices = [level["name"] for level in severity_levels_list] selected_index = q.choose( "Select an example severity level by entering a number from the preceding list:", severity_choices, ) selected_severity = severity_levels_list[selected_index] print("-" * 88) return selected_severity def create_example_case(self, service, category, severity_level): """ Creates an example support case with the user's selections. :param service: The service for the new case. :param category: The category for the new case. :param severity_level: The severity level for the new case. :return: The caseId of the new support case. """ print("-" * 88) print(f"Creating new case for service {service['name']}.") case_id = self.support_wrapper.create_case(service, category, severity_level) print(f"\tNew case created with ID {case_id}.") print("-" * 88) return case_id def list_open_cases(self): """ List the open cases for the current day. """ print("-" * 88) print("Let's list the open cases for the current day.") start_time = str(datetime.utcnow().date()) end_time = str(datetime.utcnow().date() + timedelta(days=1)) open_cases = self.support_wrapper.describe_cases(start_time, end_time, False) for case in open_cases: print(f"\tCase: {case['caseId']}: status {case['status']}.") print("-" * 88) def create_attachment_set(self): """ Create an attachment set with a sample file. :return: The attachment set ID of the new attachment set. """ print("-" * 88) print("Creating attachment set with a sample file.") attachment_set_id = self.support_wrapper.add_attachment_to_set() print(f"\tNew attachment set created with ID {attachment_set_id}.") print("-" * 88) return attachment_set_id def add_communication(self, case_id, attachment_set_id): """ Add a communication with an attachment set to the case. :param case_id: The ID of the case for the communication. :param attachment_set_id: The ID of the attachment set to add to the communication. """ print("-" * 88) print(f"Adding a communication and attachment set to the case.") self.support_wrapper.add_communication_to_case(attachment_set_id, case_id) print( f"Added a communication and attachment set {attachment_set_id} to the case {case_id}." ) print("-" * 88) def list_communications(self, case_id): """ List the communications associated with a case. :param case_id: The ID of the case. :return: The attachment ID of an attachment. """ print("-" * 88) print("Let's list the communications for our case.") attachment_id = "" communications = self.support_wrapper.describe_all_case_communications(case_id) for communication in communications: print( f"\tCommunication created on {communication['timeCreated']} " f"has {len(communication['attachmentSet'])} attachments." ) if len(communication["attachmentSet"]) > 0: attachment_id = communication["attachmentSet"][0]["attachmentId"] print("-" * 88) return attachment_id def describe_case_attachment(self, attachment_id): """ Describe an attachment associated with a case. :param attachment_id: The ID of the attachment. """ print("-" * 88) print("Let's list the communications for our case.") attached_file = self.support_wrapper.describe_attachment(attachment_id) print(f"\tAttachment includes file {attached_file}.") print("-" * 88) def resolve_case(self, case_id): """ Shows how to resolve an AWS Support case by its ID. :param case_id: The ID of the case to resolve. """ print("-" * 88) print(f"Resolving case with ID {case_id}.") case_status = self.support_wrapper.resolve_case(case_id) print(f"\tFinal case status is {case_status}.") print("-" * 88) def list_resolved_cases(self): """ List the resolved cases for the current day. """ print("-" * 88) print("Let's list the resolved cases for the current day.") start_time = str(datetime.utcnow().date()) end_time = str(datetime.utcnow().date() + timedelta(days=1)) resolved_cases = self.support_wrapper.describe_cases(start_time, end_time, True) for case in resolved_cases: print(f"\tCase: {case['caseId']}: status {case['status']}.") print("-" * 88) def run_scenario(self): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Welcome to the AWS Support get started with support cases demo.") print("-" * 88) selected_service = self.display_and_select_service() selected_category = self.display_and_select_category(selected_service) selected_severity = self.display_and_select_severity() new_case_id = self.create_example_case( selected_service, selected_category, selected_severity ) wait(10) self.list_open_cases() new_attachment_set_id = self.create_attachment_set() self.add_communication(new_case_id, new_attachment_set_id) new_attachment_id = self.list_communications(new_case_id) self.describe_case_attachment(new_attachment_id) self.resolve_case(new_case_id) wait(10) self.list_resolved_cases() print("\nThanks for watching!") print("-" * 88) if __name__ == "__main__": try: scenario = SupportCasesScenario(SupportWrapper.from_client()) scenario.run_scenario() except Exception: logging.exception("Something went wrong with the demo.")

지원 클라이언트 작업을 래핑하는 클래스를 정의합니다.

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_services(self, language): """ Get the descriptions of AWS services available for support for a language. :param language: The language for support services. Currently, only "en" (English) and "ja" (Japanese) are supported. :return: The list of AWS service descriptions. """ try: response = self.support_client.describe_services(language=language) services = response["services"] 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 Support services for language %s. Here's why: %s: %s", language, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return services 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 def create_case(self, service, category, severity): """ Create a new support case. :param service: The service to use for the new case. :param category: The category to use for the new case. :param severity: The severity to use for the new case. :return: The caseId of the new case. """ try: response = self.support_client.create_case( subject="Example case for testing, ignore.", serviceCode=service["code"], severityCode=severity["code"], categoryCode=category["code"], communicationBody="Example support case body.", language="en", issueType="customer-service", ) case_id = response["caseId"] 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 create case. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return case_id def add_attachment_to_set(self): """ Add an attachment to a set, or create a new attachment set if one does not exist. :return: The attachment set ID. """ try: response = self.support_client.add_attachments_to_set( attachments=[ { "fileName": "attachment_file.txt", "data": b"This is a sample file for attachment to a support case.", } ] ) new_set_id = response["attachmentSetId"] 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 add attachment. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return new_set_id def add_communication_to_case(self, attachment_set_id, case_id): """ Add a communication and an attachment set to a case. :param attachment_set_id: The ID of an existing attachment set. :param case_id: The ID of the case. """ try: self.support_client.add_communication_to_case( caseId=case_id, communicationBody="This is an example communication added to a support case.", attachmentSetId=attachment_set_id, ) 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 add communication. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise def describe_all_case_communications(self, case_id): """ Describe all the communications for a case using a paginator. :param case_id: The ID of the case. :return: The communications for the case. """ try: communications = [] paginator = self.support_client.get_paginator("describe_communications") for page in paginator.paginate(caseId=case_id): communications += page["communications"] 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 describe communications. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return communications def describe_attachment(self, attachment_id): """ Get information about an attachment by its attachmentID. :param attachment_id: The ID of the attachment. :return: The name of the attached file. """ try: response = self.support_client.describe_attachment( attachmentId=attachment_id ) attached_file = response["attachment"]["fileName"] 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 attachment description. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return attached_file def resolve_case(self, case_id): """ Resolve a support case by its caseId. :param case_id: The ID of the case to resolve. :return: The final status of the case. """ try: response = self.support_client.resolve_case(caseId=case_id) final_status = response["finalCaseStatus"] 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 resolve case. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return final_status def describe_cases(self, after_time, before_time, resolved): """ Describe support cases over a period of time, optionally filtering by status. :param after_time: The start time to include for cases. :param before_time: The end time to include for cases. :param resolved: True to include resolved cases in the results, otherwise results are open cases. :return: The final status of the case. """ try: cases = [] paginator = self.support_client.get_paginator("describe_cases") for page in paginator.paginate( afterTime=after_time, beforeTime=before_time, includeResolvedCases=resolved, language="en", ): cases += page["cases"] 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 describe cases. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: if resolved: cases = filter(lambda case: case["status"] == "resolved", cases) return cases

작업

다음 코드 예시에서는 AddAttachmentsToSet을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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 add_attachment_to_set(self): """ Add an attachment to a set, or create a new attachment set if one does not exist. :return: The attachment set ID. """ try: response = self.support_client.add_attachments_to_set( attachments=[ { "fileName": "attachment_file.txt", "data": b"This is a sample file for attachment to a support case.", } ] ) new_set_id = response["attachmentSetId"] 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 add attachment. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return new_set_id
  • API 세부 정보는 Word for Python(Boto3) AddAttachmentsToSet 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 AddCommunicationToCase을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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 add_communication_to_case(self, attachment_set_id, case_id): """ Add a communication and an attachment set to a case. :param attachment_set_id: The ID of an existing attachment set. :param case_id: The ID of the case. """ try: self.support_client.add_communication_to_case( caseId=case_id, communicationBody="This is an example communication added to a support case.", attachmentSetId=attachment_set_id, ) 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 add communication. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • API 세부 정보는 Word for Python(Boto3) AddCommunicationToCase 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 CreateCase을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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 create_case(self, service, category, severity): """ Create a new support case. :param service: The service to use for the new case. :param category: The category to use for the new case. :param severity: The severity to use for the new case. :return: The caseId of the new case. """ try: response = self.support_client.create_case( subject="Example case for testing, ignore.", serviceCode=service["code"], severityCode=severity["code"], categoryCode=category["code"], communicationBody="Example support case body.", language="en", issueType="customer-service", ) case_id = response["caseId"] 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 create case. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return case_id
  • API 세부 정보는 Word for Python(Boto3) CreateCase 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 DescribeAttachment을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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_attachment(self, attachment_id): """ Get information about an attachment by its attachmentID. :param attachment_id: The ID of the attachment. :return: The name of the attached file. """ try: response = self.support_client.describe_attachment( attachmentId=attachment_id ) attached_file = response["attachment"]["fileName"] 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 attachment description. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return attached_file
  • API 세부 정보는 Word for Python(Boto3) DescribeAttachment 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 DescribeCases을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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_cases(self, after_time, before_time, resolved): """ Describe support cases over a period of time, optionally filtering by status. :param after_time: The start time to include for cases. :param before_time: The end time to include for cases. :param resolved: True to include resolved cases in the results, otherwise results are open cases. :return: The final status of the case. """ try: cases = [] paginator = self.support_client.get_paginator("describe_cases") for page in paginator.paginate( afterTime=after_time, beforeTime=before_time, includeResolvedCases=resolved, language="en", ): cases += page["cases"] 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 describe cases. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: if resolved: cases = filter(lambda case: case["status"] == "resolved", cases) return cases
  • API 세부 정보는 Word for Python(Boto3) DescribeCases 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 DescribeCommunications을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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_all_case_communications(self, case_id): """ Describe all the communications for a case using a paginator. :param case_id: The ID of the case. :return: The communications for the case. """ try: communications = [] paginator = self.support_client.get_paginator("describe_communications") for page in paginator.paginate(caseId=case_id): communications += page["communications"] 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 describe communications. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return communications
  • API 세부 정보는 Word for Python(Boto3) DescribeCommunications 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 DescribeServices을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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_services(self, language): """ Get the descriptions of AWS services available for support for a language. :param language: The language for support services. Currently, only "en" (English) and "ja" (Japanese) are supported. :return: The list of AWS service descriptions. """ try: response = self.support_client.describe_services(language=language) services = response["services"] 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 Support services for language %s. Here's why: %s: %s", language, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return services
  • API 세부 정보는 Word for Python(Boto3) DescribeServices 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 DescribeSeverityLevels을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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 세부 정보는 Word for Python(Boto3) DescribeSeverityLevels 참조의 Word를 참조하세요. AWS SDK API

다음 코드 예시에서는 ResolveCase을 사용하는 방법을 보여 줍니다.

Python용 SDK(Boto3)
참고

더 많은 on 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 resolve_case(self, case_id): """ Resolve a support case by its caseId. :param case_id: The ID of the case to resolve. :return: The final status of the case. """ try: response = self.support_client.resolve_case(caseId=case_id) final_status = response["finalCaseStatus"] 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 resolve case. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return final_status
  • API 세부 정보는 Word for Python(Boto3) ResolveCase 참조의 Word를 참조하세요. AWS SDK API