AWS code-library documentation change
Summary
Updated .NET SDK version from v3 to v4, added dependency injection setup, improved logging configuration, switched to paginated API calls, and enhanced code examples with better error handling and output formatting
Security assessment
Changes focus on SDK version update and code quality improvements. No security vulnerabilities addressed. Added logging configuration appears to be standard debugging setup rather than security-related monitoring. Pagination changes improve efficiency but don't impact security
Diff
diff --git a/code-library/latest/ug/ecs_example_ecs_Hello_section.md b/code-library/latest/ug/ecs_example_ecs_Hello_section.md index 1d5d6ec6d..a6eacd09a 100644 --- a//code-library/latest/ug/ecs_example_ecs_Hello_section.md +++ b//code-library/latest/ug/ecs_example_ecs_Hello_section.md @@ -14 +14 @@ The following code example shows how to get started using Amazon ECS. -**SDK for .NET** +**SDK for .NET (v4)** @@ -19 +19 @@ The following code example shows how to get started using Amazon ECS. -There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/ECS#code-examples). +There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv4/ECS#code-examples). @@ -23,0 +24 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + using Microsoft.Extensions.DependencyInjection; @@ -24,0 +26,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Logging.Console; + using Microsoft.Extensions.Logging.Debug; @@ -27,0 +32,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + /// <summary> + /// A class that introduces the Amazon ECS Client by listing the + /// cluster ARNs for the account. + /// </summary> @@ -32 +40 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - // Use the AWS .NET Core Setup package to set up dependency injection for the Amazon ECS domain registration service. + // Use the AWS .NET Core Setup package to set up dependency injection for the Amazon ECS client. @@ -34 +42,14 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - using var host = Host.CreateDefaultBuilder(args).Build(); + 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(); @@ -36,2 +57 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - // Now the client is available for injection. - var amazonECSClient = new AmazonECSClient(); + var clusters = new List<string>(); @@ -39,2 +59 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - // You can use await and any of the async methods to get a response. - var response = await amazonECSClient.ListClustersAsync(new ListClustersRequest { }); + var clustersPaginator = amazonECSClient.Paginators.ListClusters(new ListClustersRequest()); @@ -42,3 +61,6 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - 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)) + await foreach (var response in clustersPaginator.Responses) + { + clusters.AddRange(response.ClusterArns); + } + + if (clusters.Count > 0) @@ -46,2 +68,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - Console.WriteLine($"\tARN: {arn}"); - Console.WriteLine($"Cluster Name: {arn.Split("/").Last()}"); + clusters.ForEach(cluster => + { + Console.WriteLine($"\tARN: {cluster}"); + Console.WriteLine($"Cluster Name: {cluster.Split("/").Last()}"); @@ -48,0 +73,5 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + }); + } + else + { + Console.WriteLine("No clusters were found."); @@ -55 +85 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - * For API details, see [ListClusters](https://docs.aws.amazon.com/goto/DotNetSDKV3/ecs-2014-11-13/ListClusters) in _AWS SDK for .NET API Reference_. + * For API details, see [ListClusters](https://docs.aws.amazon.com/goto/DotNetSDKV4/ecs-2014-11-13/ListClusters) in _AWS SDK for .NET API Reference_.