Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS
Hello Amazon ECS
L’esempio di codice seguente mostra come iniziare a utilizzare Amazon ECS.
- .NET
-
- SDK per .NET (v4)
-
Nota
Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice AWS
. using Amazon.ECS; using Amazon.ECS.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Console; using Microsoft.Extensions.Logging.Debug; namespace ECSActions; /// <summary> /// A class that introduces the Amazon ECS Client by listing the /// cluster ARNs for the account. /// </summary> public class HelloECS { static async System.Threading.Tasks.Task Main(string[] args) { // Use the AWS .NET Core Setup package to set up dependency injection for the Amazon ECS client. // 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<IAmazonECS>() ) .Build(); var amazonECSClient = host.Services.GetRequiredService<IAmazonECS>(); Console.WriteLine($"Hello Amazon ECS! Following are some cluster ARNS available in the your account"); Console.WriteLine(); var clusters = new List<string>(); var clustersPaginator = amazonECSClient.Paginators.ListClusters(new ListClustersRequest()); await foreach (var response in clustersPaginator.Responses) { clusters.AddRange(response.ClusterArns); } if (clusters.Count > 0) { clusters.ForEach(cluster => { Console.WriteLine($"\tARN: {cluster}"); Console.WriteLine($"Cluster Name: {cluster.Split("/").Last()}"); Console.WriteLine(); }); } else { Console.WriteLine("No clusters were found."); } } }-
Per informazioni dettagliate sull’API, consulta ListClusters nella documentazione di riferimento dell’API AWS SDK per .NET.
-
Nozioni di base
Azioni