AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2026-02-13 · Documentation low

File: code-library/latest/ug/csharp_4_s3_code_examples.md

Summary

Restructured documentation to add 'Get started' and 'Basics' sections, expanded code examples for core S3 operations including bucket creation, file upload/download, object copying, listing, and deletion. Added interactive scenario implementation and S3Wrapper helper class.

Security assessment

The changes focus on general S3 usage patterns and code structure improvements without addressing security vulnerabilities, security features, or security best practices. No evidence of security patches, vulnerability disclosures, or security-specific documentation additions exists in the diff.

Diff

diff --git a/code-library/latest/ug/csharp_4_s3_code_examples.md b/code-library/latest/ug/csharp_4_s3_code_examples.md
index 386c20072..9c925b772 100644
--- a//code-library/latest/ug/csharp_4_s3_code_examples.md
+++ b//code-library/latest/ug/csharp_4_s3_code_examples.md
@@ -5 +5 @@
-ActionsScenarios
+Get startedBasicsActionsScenarios
@@ -12,0 +13,2 @@ The following code examples show you how to perform actions and implement common
+_Basics_ are code examples that show you how to perform the essential operations within a service.
+
@@ -15 +17,689 @@ _Actions_ are code excerpts from larger programs and must be run in context. Whi
-_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.
+_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.
+
+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.
+
+###### Topics
+
+  * Get started
+
+  * Basics
+
+  * Actions
+
+  * Scenarios
+
+
+
+
+## Get started
+
+The following code example shows how to get started using Amazon S3.
+
+**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](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv4/S3#code-examples). 
+    
+    
+    /// <summary>
+    /// Hello Amazon Simple Storage Service
+    // (Amazon S3) example.
+    /// </summary>
+    public class HelloS3
+    {
+        /// <summary>
+        /// Main method to run the Hello S3 example.
+        /// </summary>
+        /// <param name="args">Command line arguments.</param>
+        /// <returns>A Task object.</returns>
+        public static async Task Main(string[] args)
+        {
+            var s3Client = new AmazonS3Client();
+    
+            try
+            {
+                Console.WriteLine("Hello Amazon S3! Let's list your buckets:");
+                Console.WriteLine(new string('-', 80));
+    
+                // Use the built-in paginator to list buckets
+                var request = new ListBucketsRequest();
+                var paginator = s3Client.Paginators.ListBuckets(request);
+    
+                var buckets = new List<S3Bucket>();
+    
+                await foreach (var response in paginator.Responses)
+                {
+                    buckets.AddRange(response.Buckets);
+                }
+    
+                if (buckets.Any())
+                {
+                    Console.WriteLine($"Found {buckets.Count} S3 buckets:");
+                    Console.WriteLine();
+    
+                    foreach (var bucket in buckets)
+                    {
+                        Console.WriteLine($"- Bucket Name: {bucket.BucketName}");
+                        Console.WriteLine($"  Creation Date: {bucket.CreationDate:yyyy-MM-dd HH:mm:ss UTC}");
+                        Console.WriteLine();
+                    }
+                }
+                else
+                {
+                    Console.WriteLine("No S3 buckets found in your account.");
+                }
+    
+                Console.WriteLine("Hello S3 completed successfully.");
+            }
+            catch (AmazonS3Exception ex)
+            {
+                Console.WriteLine($"S3 service error occurred: {ex.Message}");
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"Couldn't list S3 buckets. Here's why: {ex.Message}");
+            }
+        }
+    }
+    
+    
+
+  * For API details, see [ListBuckets](https://docs.aws.amazon.com/goto/DotNetSDKV4/s3-2006-03-01/ListBuckets) in _AWS SDK for .NET API Reference_. 
+
+
+
+
+## Basics
+
+The following code example shows how to:
+
+  * Create a bucket and upload a file to it.
+
+  * Download an object from a bucket.
+
+  * Copy an object to a subfolder in a bucket.
+
+  * List the objects in a bucket.
+
+  * Delete the bucket objects and the bucket.
+
+
+
+
+**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](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv4/S3#code-examples). 
+
+Run an interactive scenario demonstrating Amazon S3 features.
+    
+    
+    public class S3_Basics
+    {
+        public static bool IsInteractive = true;
+        public static string BucketName = null!;
+        public static string TempFilePath = null!;
+        public static S3Wrapper _s3Wrapper = null!;
+        public static ILogger<S3_Basics> _logger = null!;
+    
+        public static async Task Main(string[] args)
+        {
+            // Set up dependency injection for the Amazon service.
+            using var host = Host.CreateDefaultBuilder(args)
+                .ConfigureServices((_, services) =>
+                    services.AddAWSService<IAmazonS3>()
+                        .AddTransient<S3Wrapper>()
+                        .AddLogging(builder => builder.AddConsole()))
+                .Build();
+    
+            _logger = LoggerFactory.Create(builder => builder.AddConsole())
+                .CreateLogger<S3_Basics>();
+    
+            _s3Wrapper = host.Services.GetRequiredService<S3Wrapper>();
+    
+            var sepBar = new string('-', 45);
+    
+            Console.WriteLine(sepBar);
+            Console.WriteLine("Amazon Simple Storage Service (Amazon S3) basic");
+            Console.WriteLine("procedures. This application will:");
+            Console.WriteLine("\n\t1. Create a bucket");
+            Console.WriteLine("\n\t2. Upload an object to the new bucket");
+            Console.WriteLine("\n\t3. Copy the uploaded object to a folder in the bucket");
+            Console.WriteLine("\n\t4. List the items in the new bucket");
+            Console.WriteLine("\n\t5. Delete all the items in the bucket");
+            Console.WriteLine("\n\t6. Delete the bucket");
+            Console.WriteLine(sepBar);
+    
+            await RunScenario(_s3Wrapper, _logger);
+    
+            Console.WriteLine(sepBar);
+            Console.WriteLine("The Amazon S3 scenario has successfully completed.");
+            Console.WriteLine(sepBar);
+        }
+    
+        /// <summary>
+        /// Run the S3 Basics scenario with injected dependencies.
+        /// </summary>
+        /// <param name="s3Wrapper">The S3 wrapper instance.</param>
+        /// <param name="scenarioLogger">The logger instance.</param>
+        /// <returns>A Task object.</returns>
+        public static async Task RunScenario(S3Wrapper s3Wrapper, ILogger<S3_Basics> scenarioLogger)
+        {
+            string bucketName = BucketName;
+            string filePath = TempFilePath;
+            string keyName = string.Empty;
+    
+            var sepBar = new string('-', 45);
+    
+            try
+            {
+                // Create a bucket.
+                Console.WriteLine($"\n{sepBar}");
+                Console.WriteLine("\nCreate a new Amazon S3 bucket.\n");
+                Console.WriteLine(sepBar);
+