AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-06-28 · Documentation low

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

Summary

Added Python (Boto3) code example for DescribeDBInstances with instance status monitoring and error handling

Security assessment

The change adds operational monitoring documentation without security-specific content. Error handling for DBInstanceNotFound is standard API usage guidance with no security implications.

Diff

diff --git a/code-library/latest/ug/neptune_example_neptune_DescribeDBInstances_section.md b/code-library/latest/ug/neptune_example_neptune_DescribeDBInstances_section.md
index 7f36d9a7d..fd332ed7b 100644
--- a//code-library/latest/ug/neptune_example_neptune_DescribeDBInstances_section.md
+++ b//code-library/latest/ug/neptune_example_neptune_DescribeDBInstances_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 `DescribeDBInstances`.
+The following code examples show how to use `DescribeDBInstances`.
@@ -72,0 +73,62 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+Python
+    
+
+**SDK for Python (Boto3)**
+    
+
+###### 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/python/example_code/neptune#code-examples). 
+    
+    
+    def check_instance_status(neptune_client, instance_id: str, desired_status: str):
+        """
+        Polls the status of a Neptune DB instance until it reaches desired_status.
+        Uses pagination via describe_db_instances — even for a single instance.
+    
+        Raises:
+          ClientError: If describe_db_instances fails (e.g., instance not found).
+          RuntimeError: If timeout expires before reaching desired status.
+        """
+        paginator = neptune_client.get_paginator('describe_db_instances')
+        start_time = time.time()
+    
+        while True:
+            try:
+                pages = paginator.paginate(DBInstanceIdentifier=instance_id)
+                instances = []
+                for page in pages:
+                    instances.extend(page.get('DBInstances', []))
+    
+            except ClientError as err:
+                code = err.response["Error"]["Code"]
+                message = err.response["Error"]["Message"]
+    
+                if code == "DBInstanceNotFound":
+                    print(f"Instance '{instance_id}' not found. Please verify the instance ID.")
+                else:
+                    print(f"Failed to describe DB instance. {code}: {message}")
+                raise
+    
+            current_status = instances[0].get('DBInstanceStatus') if instances else None
+            elapsed = int(time.time() - start_time)
+    
+            print(f"\rElapsed: {format_elapsed_time(elapsed)}  Status: {current_status}", end="", flush=True)
+    
+            if current_status and current_status.lower() == desired_status.lower():
+                print(f"\nInstance '{instance_id}' reached '{desired_status}' in {format_elapsed_time(elapsed)}.")
+                return
+    
+            if elapsed > TIMEOUT_SECONDS:
+                raise RuntimeError(f"Timeout waiting for '{instance_id}' to reach '{desired_status}'")
+    
+            time.sleep(POLL_INTERVAL_SECONDS)
+    
+    
+    
+
+  * For API details, see [DescribeDBInstances](https://docs.aws.amazon.com/goto/boto3/neptune-2014-10-31/DescribeDBInstances) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+