Code examples for Amazon ECS using AWS SDKs - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Code examples for Amazon ECS using AWS SDKs

The following code examples show you how to use Amazon Elastic Container Service with an AWS software development kit (SDK).

Basics are code examples that show you how to perform the essential operations within a service.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Scenarios are code examples that show you how to accomplish specific tasks by calling multiple functions within a service or combined with other AWS services.

More resources

Get started

The following code example shows how to get started using Amazon ECS.

.NET
AWS SDK for .NET
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.Hosting; namespace ECSActions; 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 domain registration service. // Use your AWS profile name, or leave it blank to use the default profile. using var host = Host.CreateDefaultBuilder(args).Build(); // Now the client is available for injection. var amazonECSClient = new AmazonECSClient(); // You can use await and any of the async methods to get a response. var response = await amazonECSClient.ListClustersAsync(new ListClustersRequest { }); Console.WriteLine($"Hello Amazon ECS! Following are some cluster ARNS available in the your aws account"); Console.WriteLine(); foreach (var arn in response.ClusterArns.Take(5)) { Console.WriteLine($"\tARN: {arn}"); Console.WriteLine($"Cluster Name: {arn.Split("/").Last()}"); Console.WriteLine(); } } }
  • For API details, see ListClusters in AWS SDK for .NET API Reference.