AWS Support 사용 예제 AWS SDK for .NET - AWS SDK코드 예제

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

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

AWS Support 사용 예제 AWS SDK for .NET

다음 코드 예제는 with 를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다 AWS Support. AWS SDK for .NET

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

시나리오는 동일한 서비스 내에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예시입니다.

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

시작하기

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

AWS SDK for .NET
참고

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

using Amazon.AWSSupport; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; public static class HelloSupport { static async Task Main(string[] args) { // Use the AWS .NET Core Setup package to set up dependency injection for the AWS Support service. // Use your AWS profile name, or leave it blank to use the default profile. // You must have one of the following AWS Support plans: Business, Enterprise On-Ramp, or Enterprise. Otherwise, an exception will be thrown. using var host = Host.CreateDefaultBuilder(args) .ConfigureServices((_, services) => services.AddAWSService<IAmazonAWSSupport>() ).Build(); // Now the client is available for injection. var supportClient = host.Services.GetRequiredService<IAmazonAWSSupport>(); // You can use await and any of the async methods to get a response. var response = await supportClient.DescribeServicesAsync(); Console.WriteLine($"\tHello AWS Support! There are {response.Services.Count} services available."); } }

작업

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

AWS SDK for .NET
참고

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

/// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Add communication to a case, including optional attachment set ID and CC email addresses. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <param name="body">Body text of the communication.</param> /// <param name="attachmentSetId">Optional Id for an attachment set.</param> /// <param name="ccEmailAddresses">Optional list of CC email addresses.</param> /// <returns>True if successful.</returns> public async Task<bool> AddCommunicationToCase(string caseId, string body, string? attachmentSetId = null, List<string>? ccEmailAddresses = null) { var response = await _amazonSupport.AddCommunicationToCaseAsync( new AddCommunicationToCaseRequest() { CaseId = caseId, CommunicationBody = body, AttachmentSetId = attachmentSetId, CcEmailAddresses = ccEmailAddresses }); return response.Result; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Create a new support case. /// </summary> /// <param name="serviceCode">Service code for the new case.</param> /// <param name="categoryCode">Category for the new case.</param> /// <param name="severityCode">Severity code for the new case.</param> /// <param name="subject">Subject of the new case.</param> /// <param name="body">Body text of the new case.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <param name="attachmentSetId">Optional Id for an attachment set for the new case.</param> /// <param name="issueType">Optional issue type for the new case. Options are "customer-service" or "technical".</param> /// <returns>The caseId of the new support case.</returns> public async Task<string> CreateCase(string serviceCode, string categoryCode, string severityCode, string subject, string body, string language = "en", string? attachmentSetId = null, string issueType = "customer-service") { var response = await _amazonSupport.CreateCaseAsync( new CreateCaseRequest() { ServiceCode = serviceCode, CategoryCode = categoryCode, SeverityCode = severityCode, Subject = subject, Language = language, AttachmentSetId = attachmentSetId, IssueType = issueType, CommunicationBody = body }); return response.CaseId; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Get description of a specific attachment. /// </summary> /// <param name="attachmentId">Id of the attachment, usually fetched by describing the communications of a case.</param> /// <returns>The attachment object.</returns> public async Task<Attachment> DescribeAttachment(string attachmentId) { var response = await _amazonSupport.DescribeAttachmentAsync( new DescribeAttachmentRequest() { AttachmentId = attachmentId }); return response.Attachment; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Get case details for a list of case ids, optionally with date filters. /// </summary> /// <param name="caseIds">The list of case IDs.</param> /// <param name="displayId">Optional display ID.</param> /// <param name="includeCommunication">True to include communication. Defaults to true.</param> /// <param name="includeResolvedCases">True to include resolved cases. Defaults to false.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>A list of CaseDetails.</returns> public async Task<List<CaseDetails>> DescribeCases(List<string> caseIds, string? displayId = null, bool includeCommunication = true, bool includeResolvedCases = false, DateTime? afterTime = null, DateTime? beforeTime = null, string language = "en") { var results = new List<CaseDetails>(); var paginateCases = _amazonSupport.Paginators.DescribeCases( new DescribeCasesRequest() { CaseIdList = caseIds, DisplayId = displayId, IncludeCommunications = includeCommunication, IncludeResolvedCases = includeResolvedCases, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s"), Language = language }); // Get the entire list using the paginator. await foreach (var cases in paginateCases.Cases) { results.Add(cases); } return results; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Describe the communications for a case, optionally with a date filter. /// </summary> /// <param name="caseId">The ID of the support case.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <returns>The list of communications for the case.</returns> public async Task<List<Communication>> DescribeCommunications(string caseId, DateTime? afterTime = null, DateTime? beforeTime = null) { var results = new List<Communication>(); var paginateCommunications = _amazonSupport.Paginators.DescribeCommunications( new DescribeCommunicationsRequest() { CaseId = caseId, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s") }); // Get the entire list using the paginator. await foreach (var communications in paginateCommunications.Communications) { results.Add(communications); } return results; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Get the descriptions of AWS services. /// </summary> /// <param name="name">Optional language for services. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of AWS service descriptions.</returns> public async Task<List<Service>> DescribeServices(string language = "en") { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = language }); return response.Services; }

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

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; }

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

AWS SDK for .NET
참고

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

/// <summary> /// Resolve a support case by caseId. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <returns>The final status of the case after resolving.</returns> public async Task<string> ResolveCase(string caseId) { var response = await _amazonSupport.ResolveCaseAsync( new ResolveCaseRequest() { CaseId = caseId }); return response.FinalCaseStatus; }

시나리오

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

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

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

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

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

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

  • 사건을 해결하세요.

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

AWS SDK for .NET
참고

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

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

/// <summary> /// Hello AWS Support example. /// </summary> public static class SupportCaseScenario { /* Before running this .NET code example, set up your development environment, including your credentials. To use the AWS Support API, you must have one of the following AWS Support plans: Business, Enterprise On-Ramp, or Enterprise. This .NET example performs the following tasks: 1. Get and display services. Select a service from the list. 2. Select a category from the selected service. 3. Get and display severity levels and select a severity level from the list. 4. Create a support case using the selected service, category, and severity level. 5. Get and display a list of open support cases for the current day. 6. Create an attachment set with a sample text file to add to the case. 7. Add a communication with the attachment to the support case. 8. List the communications of the support case. 9. Describe the attachment set. 10. Resolve the support case. 11. Get a list of resolved cases for the current day. */ private static SupportWrapper _supportWrapper = null!; static async Task Main(string[] args) { // Set up dependency injection for the AWS Support service. // Use your AWS profile name, or leave it blank to use the default profile. using var host = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.AddFilter("System", LogLevel.Debug) .AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information) .AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace)) .ConfigureServices((_, services) => services.AddAWSService<IAmazonAWSSupport>(new AWSOptions() { Profile = "default" }) .AddTransient<SupportWrapper>() ) .Build(); var logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger(typeof(SupportCaseScenario)); _supportWrapper = host.Services.GetRequiredService<SupportWrapper>(); Console.WriteLine(new string('-', 80)); Console.WriteLine("Welcome to the AWS Support case example scenario."); Console.WriteLine(new string('-', 80)); try { var apiSupported = await _supportWrapper.VerifySubscription(); if (!apiSupported) { logger.LogError("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."); return; } var service = await DisplayAndSelectServices(); var category = DisplayAndSelectCategories(service); var severityLevel = await DisplayAndSelectSeverity(); var caseId = await CreateSupportCase(service, category, severityLevel); await DescribeTodayOpenCases(); var attachmentSetId = await CreateAttachmentSet(); await AddCommunicationToCase(attachmentSetId, caseId); var attachmentId = await ListCommunicationsForCase(caseId); await DescribeCaseAttachment(attachmentId); await ResolveCase(caseId); await DescribeTodayResolvedCases(); Console.WriteLine(new string('-', 80)); Console.WriteLine("AWS Support case example scenario complete."); Console.WriteLine(new string('-', 80)); } catch (Exception ex) { logger.LogError(ex, "There was a problem executing the scenario."); } } /// <summary> /// List some available services from AWS Support, and select a service for the example. /// </summary> /// <returns>The selected service.</returns> private static async Task<Service> DisplayAndSelectServices() { Console.WriteLine(new string('-', 80)); var services = await _supportWrapper.DescribeServices(); Console.WriteLine($"AWS Support client returned {services.Count} services."); Console.WriteLine($"1. Displaying first 10 services:"); for (int i = 0; i < 10 && i < services.Count; i++) { Console.WriteLine($"\t{i + 1}. {services[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > services.Count) { Console.WriteLine( "Select an example support service by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return services[choiceNumber - 1]; } /// <summary> /// List the available categories for a service and select a category for the example. /// </summary> /// <param name="service">Service to use for displaying categories.</param> /// <returns>The selected category.</returns> private static Category DisplayAndSelectCategories(Service service) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"2. Available support categories for Service \"{service.Name}\":"); for (int i = 0; i < service.Categories.Count; i++) { Console.WriteLine($"\t{i + 1}. {service.Categories[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > service.Categories.Count) { Console.WriteLine( "Select an example support category by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return service.Categories[choiceNumber - 1]; } /// <summary> /// List available severity levels from AWS Support, and select a level for the example. /// </summary> /// <returns>The selected severity level.</returns> private static async Task<SeverityLevel> DisplayAndSelectSeverity() { Console.WriteLine(new string('-', 80)); var severityLevels = await _supportWrapper.DescribeSeverityLevels(); Console.WriteLine($"3. Get and display available severity levels:"); for (int i = 0; i < 10 && i < severityLevels.Count; i++) { Console.WriteLine($"\t{i + 1}. {severityLevels[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > severityLevels.Count) { Console.WriteLine( "Select an example severity level by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return severityLevels[choiceNumber - 1]; } /// <summary> /// Create an example support case. /// </summary> /// <param name="service">Service to use for the new case.</param> /// <param name="category">Category to use for the new case.</param> /// <param name="severity">Severity to use for the new case.</param> /// <returns>The caseId of the new support case.</returns> private static async Task<string> CreateSupportCase(Service service, Category category, SeverityLevel severity) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"4. Create an example support case" + $" with the following settings:" + $" \n\tService: {service.Name}, Category: {category.Name} " + $"and Severity Level: {severity.Name}."); var caseId = await _supportWrapper.CreateCase(service.Code, category.Code, severity.Code, "Example case for testing, ignore.", "This is my example support case."); Console.WriteLine($"\tNew case created with ID {caseId}"); Console.WriteLine(new string('-', 80)); return caseId; } /// <summary> /// List open cases for the current day. /// </summary> /// <returns>Async task.</returns> private static async Task DescribeTodayOpenCases() { Console.WriteLine($"5. List the open support cases for the current day."); // Describe the cases. If it is empty, try again and allow time for the new case to appear. List<CaseDetails> currentOpenCases = null!; while (currentOpenCases == null || currentOpenCases.Count == 0) { Thread.Sleep(1000); currentOpenCases = await _supportWrapper.DescribeCases( new List<string>(), null, false, false, DateTime.UtcNow.Date, DateTime.UtcNow); } foreach (var openCase in currentOpenCases) { Console.WriteLine($"\tCase: {openCase.CaseId} created {openCase.TimeCreated}"); } Console.WriteLine(new string('-', 80)); } /// <summary> /// Create an attachment set for a support case. /// </summary> /// <returns>The attachment set id.</returns> private static async Task<string> CreateAttachmentSet() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"6. Create an attachment set for a support case."); var fileName = "example_attachment.txt"; // Create the file if it does not already exist. if (!File.Exists(fileName)) { await using StreamWriter sw = File.CreateText(fileName); await sw.WriteLineAsync( "This is a sample file for attachment to a support case."); } await using var ms = new MemoryStream(await File.ReadAllBytesAsync(fileName)); var attachmentSetId = await _supportWrapper.AddAttachmentToSet( ms, fileName); Console.WriteLine($"\tNew attachment set created with id: \n\t{attachmentSetId.Substring(0, 65)}..."); Console.WriteLine(new string('-', 80)); return attachmentSetId; } /// <summary> /// Add an attachment set and communication to a case. /// </summary> /// <param name="attachmentSetId">Id of the attachment set.</param> /// <param name="caseId">Id of the case to receive the attachment set.</param> /// <returns>Async task.</returns> private static async Task AddCommunicationToCase(string attachmentSetId, string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"7. Add attachment set and communication to {caseId}."); await _supportWrapper.AddCommunicationToCase( caseId, "This is an example communication added to a support case.", attachmentSetId); Console.WriteLine($"\tNew attachment set and communication added to {caseId}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// List the communications for a case. /// </summary> /// <param name="caseId">Id of the case to describe.</param> /// <returns>An attachment id.</returns> private static async Task<string> ListCommunicationsForCase(string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"8. List communications for case {caseId}."); var communications = await _supportWrapper.DescribeCommunications(caseId); var attachmentId = ""; foreach (var communication in communications) { Console.WriteLine( $"\tCommunication created on: {communication.TimeCreated} has {communication.AttachmentSet.Count} attachments."); if (communication.AttachmentSet.Any()) { attachmentId = communication.AttachmentSet.First().AttachmentId; } } Console.WriteLine(new string('-', 80)); return attachmentId; } /// <summary> /// Describe an attachment by id. /// </summary> /// <param name="attachmentId">Id of the attachment to describe.</param> /// <returns>Async task.</returns> private static async Task DescribeCaseAttachment(string attachmentId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"9. Describe the attachment set."); var attachment = await _supportWrapper.DescribeAttachment(attachmentId); var data = Encoding.ASCII.GetString(attachment.Data.ToArray()); Console.WriteLine($"\tAttachment includes {attachment.FileName} with data: \n\t{data}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// Resolve the support case. /// </summary> /// <param name="caseId">Id of the case to resolve.</param> /// <returns>Async task.</returns> private static async Task ResolveCase(string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"10. Resolve case {caseId}."); var status = await _supportWrapper.ResolveCase(caseId); Console.WriteLine($"\tCase {caseId} has final status {status}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// List resolved cases for the current day. /// </summary> /// <returns>Async Task.</returns> private static async Task DescribeTodayResolvedCases() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"11. List the resolved support cases for the current day."); var currentCases = await _supportWrapper.DescribeCases( new List<string>(), null, false, true, DateTime.UtcNow.Date, DateTime.UtcNow); foreach (var currentCase in currentCases) { if (currentCase.Status == "resolved") { Console.WriteLine( $"\tCase: {currentCase.CaseId}: status {currentCase.Status}"); } } Console.WriteLine(new string('-', 80)); } }

시나리오에서 AWS Support 액션에 사용하는 래퍼 메서드.

/// <summary> /// Wrapper methods to use AWS Support for working with support cases. /// </summary> public class SupportWrapper { private readonly IAmazonAWSSupport _amazonSupport; public SupportWrapper(IAmazonAWSSupport amazonSupport) { _amazonSupport = amazonSupport; } /// <summary> /// Get the descriptions of AWS services. /// </summary> /// <param name="name">Optional language for services. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of AWS service descriptions.</returns> public async Task<List<Service>> DescribeServices(string language = "en") { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = language }); return response.Services; } /// <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; } /// <summary> /// Create a new support case. /// </summary> /// <param name="serviceCode">Service code for the new case.</param> /// <param name="categoryCode">Category for the new case.</param> /// <param name="severityCode">Severity code for the new case.</param> /// <param name="subject">Subject of the new case.</param> /// <param name="body">Body text of the new case.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <param name="attachmentSetId">Optional Id for an attachment set for the new case.</param> /// <param name="issueType">Optional issue type for the new case. Options are "customer-service" or "technical".</param> /// <returns>The caseId of the new support case.</returns> public async Task<string> CreateCase(string serviceCode, string categoryCode, string severityCode, string subject, string body, string language = "en", string? attachmentSetId = null, string issueType = "customer-service") { var response = await _amazonSupport.CreateCaseAsync( new CreateCaseRequest() { ServiceCode = serviceCode, CategoryCode = categoryCode, SeverityCode = severityCode, Subject = subject, Language = language, AttachmentSetId = attachmentSetId, IssueType = issueType, CommunicationBody = body }); return response.CaseId; } /// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; } /// <summary> /// Get description of a specific attachment. /// </summary> /// <param name="attachmentId">Id of the attachment, usually fetched by describing the communications of a case.</param> /// <returns>The attachment object.</returns> public async Task<Attachment> DescribeAttachment(string attachmentId) { var response = await _amazonSupport.DescribeAttachmentAsync( new DescribeAttachmentRequest() { AttachmentId = attachmentId }); return response.Attachment; } /// <summary> /// Add communication to a case, including optional attachment set ID and CC email addresses. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <param name="body">Body text of the communication.</param> /// <param name="attachmentSetId">Optional Id for an attachment set.</param> /// <param name="ccEmailAddresses">Optional list of CC email addresses.</param> /// <returns>True if successful.</returns> public async Task<bool> AddCommunicationToCase(string caseId, string body, string? attachmentSetId = null, List<string>? ccEmailAddresses = null) { var response = await _amazonSupport.AddCommunicationToCaseAsync( new AddCommunicationToCaseRequest() { CaseId = caseId, CommunicationBody = body, AttachmentSetId = attachmentSetId, CcEmailAddresses = ccEmailAddresses }); return response.Result; } /// <summary> /// Describe the communications for a case, optionally with a date filter. /// </summary> /// <param name="caseId">The ID of the support case.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <returns>The list of communications for the case.</returns> public async Task<List<Communication>> DescribeCommunications(string caseId, DateTime? afterTime = null, DateTime? beforeTime = null) { var results = new List<Communication>(); var paginateCommunications = _amazonSupport.Paginators.DescribeCommunications( new DescribeCommunicationsRequest() { CaseId = caseId, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s") }); // Get the entire list using the paginator. await foreach (var communications in paginateCommunications.Communications) { results.Add(communications); } return results; } /// <summary> /// Get case details for a list of case ids, optionally with date filters. /// </summary> /// <param name="caseIds">The list of case IDs.</param> /// <param name="displayId">Optional display ID.</param> /// <param name="includeCommunication">True to include communication. Defaults to true.</param> /// <param name="includeResolvedCases">True to include resolved cases. Defaults to false.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>A list of CaseDetails.</returns> public async Task<List<CaseDetails>> DescribeCases(List<string> caseIds, string? displayId = null, bool includeCommunication = true, bool includeResolvedCases = false, DateTime? afterTime = null, DateTime? beforeTime = null, string language = "en") { var results = new List<CaseDetails>(); var paginateCases = _amazonSupport.Paginators.DescribeCases( new DescribeCasesRequest() { CaseIdList = caseIds, DisplayId = displayId, IncludeCommunications = includeCommunication, IncludeResolvedCases = includeResolvedCases, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s"), Language = language }); // Get the entire list using the paginator. await foreach (var cases in paginateCases.Cases) { results.Add(cases); } return results; } /// <summary> /// Resolve a support case by caseId. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <returns>The final status of the case after resolving.</returns> public async Task<string> ResolveCase(string caseId) { var response = await _amazonSupport.ResolveCaseAsync( new ResolveCaseRequest() { CaseId = caseId }); return response.FinalCaseStatus; } /// <summary> /// Verify the support level for AWS Support API access. /// </summary> /// <returns>True if the subscription level supports API access.</returns> public async Task<bool> VerifySubscription() { try { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = "en" }); return response.HttpStatusCode == HttpStatusCode.OK; } catch (Amazon.AWSSupport.AmazonAWSSupportException ex) { if (ex.ErrorCode == "SubscriptionRequiredException") { return false; } else throw; } } }