There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon ECS examples using SDK for .NET (v4)
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for .NET (v4) with Amazon ECS.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Get started
The following code example shows how to get started using Amazon ECS.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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."); } } }
-
For API details, see ListClusters in AWS SDK for .NET API Reference.
-