AWS code-library documentation change
Summary
Added Python SDK example for DeleteDBInstance with deletion waiter and permission checks
Security assessment
The change demonstrates proper instance deletion patterns but does not introduce security documentation or address vulnerabilities. AccessDenied handling is routine error management rather than security guidance.
Diff
diff --git a/code-library/latest/ug/neptune_example_neptune_DeleteDBInstance_section.md b/code-library/latest/ug/neptune_example_neptune_DeleteDBInstance_section.md index df08be34e..8984646ac 100644 --- a//code-library/latest/ug/neptune_example_neptune_DeleteDBInstance_section.md +++ b//code-library/latest/ug/neptune_example_neptune_DeleteDBInstance_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 `DeleteDBInstance`. +The following code examples show how to use `DeleteDBInstance`. @@ -44,0 +45,54 @@ 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 delete_db_instance(neptune_client, instance_id: str): + """ + Deletes a Neptune DB instance and waits for its deletion to complete. + Raises exception to be handled by calling code. + """ + print(f"Initiating deletion of DB Instance: {instance_id}") + try: + neptune_client.delete_db_instance( + DBInstanceIdentifier=instance_id, + SkipFinalSnapshot=True + ) + + print(f"Waiting for DB Instance '{instance_id}' to be deleted...") + waiter = neptune_client.get_waiter('db_instance_deleted') + waiter.wait( + DBInstanceIdentifier=instance_id, + WaiterConfig={ + 'Delay': 30, + 'MaxAttempts': 40 + } + ) + + print(f"DB Instance '{instance_id}' successfully deleted.") + + except ClientError as err: + code = err.response["Error"]["Code"] + message = err.response["Error"]["Message"] + + if code == "DBInstanceNotFoundFault": + print(f"Instance '{instance_id}' not found or already deleted.") + elif code == "AccessDeniedException": + print("Access denied. Please ensure you have the necessary permissions.") + else: + print(f"Couldn't delete DB instance. {code}: {message}") + raise + + + + * For API details, see [DeleteDBInstance](https://docs.aws.amazon.com/goto/boto3/neptune-2014-10-31/DeleteDBInstance) in _AWS SDK for Python (Boto3) API Reference_. + + + +