AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-07-16 · Documentation low

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

Summary

Added .NET SDK v4 code example for EnableBaseline API with parameter documentation, error handling, and operation status polling

Security assessment

The change adds documentation for enabling security baselines (a security feature) but does not address a specific vulnerability. The example demonstrates proper implementation of security controls through baseline management.

Diff

diff --git a/code-library/latest/ug/controltower_example_controltower_EnableBaseline_section.md b/code-library/latest/ug/controltower_example_controltower_EnableBaseline_section.md
index 648186435..b950a505d 100644
--- a//code-library/latest/ug/controltower_example_controltower_EnableBaseline_section.md
+++ b//code-library/latest/ug/controltower_example_controltower_EnableBaseline_section.md
@@ -9 +9 @@ There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://
-The following code example shows how to use `EnableBaseline`.
+The following code examples show how to use `EnableBaseline`.
@@ -17,0 +18,77 @@ Action examples are code excerpts from larger programs and must be run in contex
+.NET
+    
+
+**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/ControlTower#code-examples). 
+    
+    
+        /// <summary>
+        /// Enable a baseline for the specified target.
+        /// </summary>
+        /// <param name="targetIdentifier">The ARN of the target.</param>
+        /// <param name="baselineIdentifier">The identifier of baseline to enable.</param>
+        /// <param name="baselineVersion">The version of baseline to enable.</param>
+        /// <param name="identityCenterBaseline">The identifier of identity center baseline if it is enabled.</param>
+        /// <returns>The enabled baseline ARN or null if already enabled.</returns>
+        public async Task<string?> EnableBaselineAsync(string targetIdentifier, string baselineIdentifier, string baselineVersion, string identityCenterBaseline)
+        {
+            try
+            {
+                var parameters = new List<EnabledBaselineParameter>
+                {
+                    new EnabledBaselineParameter
+                    {
+                        Key = "IdentityCenterEnabledBaselineArn",
+                        Value = identityCenterBaseline
+                    }
+                };
+    
+                var request = new EnableBaselineRequest
+                {
+                    BaselineIdentifier = baselineIdentifier,
+                    BaselineVersion = baselineVersion,
+                    TargetIdentifier = targetIdentifier,
+                    Parameters = parameters
+                };
+    
+                var response = await _controlTowerService.EnableBaselineAsync(request);
+                var operationId = response.OperationIdentifier;
+    
+                // Wait for operation to complete
+                while (true)
+                {
+                    var status = await GetBaselineOperationAsync(operationId);
+                    Console.WriteLine($"Baseline operation status: {status}");
+                    if (status == BaselineOperationStatus.SUCCEEDED || status == BaselineOperationStatus.FAILED)
+                    {
+                        break;
+                    }
+                    await Task.Delay(30000); // Wait 30 seconds
+                }
+    
+                return response.Arn;
+            }
+            catch (ValidationException ex) when (ex.Message.Contains("already enabled"))
+            {
+                Console.WriteLine("Baseline is already enabled for this target");
+                return null;
+            }
+            catch (AmazonControlTowerException ex)
+            {
+                Console.WriteLine($"Couldn't enable baseline. Here's why: {ex.ErrorCode}: {ex.Message}");
+                throw;
+            }
+        }
+    
+    
+    
+
+  * For API details, see [EnableBaseline](https://docs.aws.amazon.com/goto/DotNetSDKV4/controltower-2018-05-10/EnableBaseline) in _AWS SDK for .NET API Reference_. 
+
+
+
+