AWS code-library documentation change
Summary
Updated .NET SDK version from v3 to v4, added dependency injection setup, improved error handling, and modernized code structure for DynamoDB example
Security assessment
The changes focus on SDK version updates, code modernization (dependency injection), and error handling improvements. No explicit security vulnerabilities, encryption, authentication, or access control mechanisms were added/modified. Error handling improvements are general reliability enhancements rather than security fixes.
Diff
diff --git a/code-library/latest/ug/dynamodb_example_dynamodb_Hello_section.md b/code-library/latest/ug/dynamodb_example_dynamodb_Hello_section.md index 67c67bc32..36149a330 100644 --- a//code-library/latest/ug/dynamodb_example_dynamodb_Hello_section.md +++ b//code-library/latest/ug/dynamodb_example_dynamodb_Hello_section.md @@ -14 +14 @@ The following code examples show how to get started using DynamoDB. -**SDK for .NET** +**SDK for .NET (v4)** @@ -19 +19 @@ The following code examples show how to get started using DynamoDB. -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/dynamodb#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/DynamoDB#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; @@ -25 +26 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - namespace DynamoDB_Actions; + namespace DynamoDBActions; @@ -27 +28,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - public static class HelloDynamoDB + /// <summary> + /// A simple example that demonstrates basic DynamoDB operations. + /// </summary> + public class HelloDynamoDB @@ -28,0 +33,5 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + /// <summary> + /// HelloDynamoDB lists the existing DynamoDB tables for the default user. + /// </summary> + /// <param name="args">Command line arguments</param> + /// <returns>Async task.</returns> @@ -31 +40,6 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - var dynamoDbClient = new AmazonDynamoDBClient(); + // Set up dependency injection for Amazon DynamoDB. + using var host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) + .ConfigureServices((_, services) => + services.AddAWSService<IAmazonDynamoDB>() + ) + .Build(); @@ -33,2 +47,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - Console.WriteLine($"Hello Amazon Dynamo DB! Following are some of your tables:"); - Console.WriteLine(); + // Now the client is available for injection. + var dynamoDbClient = host.Services.GetRequiredService<IAmazonDynamoDB>(); @@ -36,4 +50 @@ 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. - // Let's get the first five tables. - var response = await dynamoDbClient.ListTablesAsync( - new ListTablesRequest() + try @@ -41,2 +52,9 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - Limit = 5 - }); + var request = new ListTablesRequest(); + var tableNames = new List<string>(); + + var paginatorForTables = dynamoDbClient.Paginators.ListTables(request); + + await foreach (var tableName in paginatorForTables.TableNames) + { + tableNames.Add(tableName); + } @@ -44 +62,12 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - foreach (var table in response.TableNames) + Console.WriteLine("Welcome to the DynamoDB Hello Service example. " + + "\nLet's list your DynamoDB tables:"); + tableNames.ForEach(table => + { + Console.WriteLine($"Table: {table}"); + }); + } + catch (AmazonDynamoDBException ex) + { + Console.WriteLine($"An Amazon DynamoDB service error occurred while listing tables. {ex.Message}"); + } + catch (Exception ex) @@ -46,2 +75 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - Console.WriteLine($"\tTable: {table}"); - Console.WriteLine(); + Console.WriteLine($"An error occurred while listing tables. {ex.Message}"); @@ -55 +83 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - * For API details, see [ListTables](https://docs.aws.amazon.com/goto/DotNetSDKV3/dynamodb-2012-08-10/ListTables) in _AWS SDK for .NET API Reference_. + * For API details, see [ListTables](https://docs.aws.amazon.com/goto/DotNetSDKV4/dynamodb-2012-08-10/ListTables) in _AWS SDK for .NET API Reference_.