AWS Security ChangesHomeSearch

AWS code-library documentation change

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

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

Summary

Added Python example for creating Neptune DB instances with error handling

Security assessment

Standard database provisioning example without security-specific configurations or vulnerability mitigations

Diff

diff --git a/code-library/latest/ug/neptune_example_neptune_CreateDBInstance_section.md b/code-library/latest/ug/neptune_example_neptune_CreateDBInstance_section.md
index d1a98b562..b39608972 100644
--- a//code-library/latest/ug/neptune_example_neptune_CreateDBInstance_section.md
+++ b//code-library/latest/ug/neptune_example_neptune_CreateDBInstance_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 `CreateDBInstance`.
+The following code examples show how to use `CreateDBInstance`.
@@ -63,0 +64,59 @@ 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 create_db_instance(neptune_client, db_instance_id: str, db_cluster_id: str) -> str:
+        try:
+            request = {
+                'DBInstanceIdentifier': db_instance_id,
+                'DBInstanceClass': 'db.r5.large',
+                'Engine': 'neptune',
+                'DBClusterIdentifier': db_cluster_id
+            }
+    
+            print(f"Creating Neptune DB Instance: {db_instance_id}")
+            response = neptune_client.create_db_instance(**request)
+    
+            instance = response.get('DBInstance')
+            if not instance or 'DBInstanceIdentifier' not in instance:
+                raise RuntimeError("Instance creation succeeded but no ID returned.")
+    
+            print(f"Waiting for DB Instance '{db_instance_id}' to become available...")
+            waiter = neptune_client.get_waiter('db_instance_available')
+            waiter.wait(
+                DBInstanceIdentifier=db_instance_id,
+                WaiterConfig={'Delay': 30, 'MaxAttempts': 40}
+            )
+    
+            print(f"DB Instance '{db_instance_id}' is now available.")
+            return instance['DBInstanceIdentifier']
+    
+        except ClientError as err:
+            code = err.response["Error"]["Code"]
+            message = err.response["Error"]["Message"]
+    
+            if code == "AccessDeniedException":
+                print("Access denied. Please ensure you have the necessary permissions.")
+            else:
+                print(f"Couldn't create DB instance. Here's why: {code}: {message}")
+            raise
+    
+        except Exception as e:
+            print(f"Unexpected error creating DB instance '{db_instance_id}': {e}")
+            raise RuntimeError(f"Unexpected error creating DB instance '{db_instance_id}': {e}") from e
+    
+    
+    
+
+  * For API details, see [CreateDBInstance](https://docs.aws.amazon.com/goto/boto3/neptune-2014-10-31/CreateDBInstance) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+