AWS code-library documentation change
Summary
Added Python (Boto3) code example for DescribeDBClusters with security configuration details like VPC security groups, storage encryption status, and IAM authentication
Security assessment
The change documents how to retrieve security-related cluster configurations (encryption, IAM auth, VPC groups), helping users audit security settings. However, this is informational rather than addressing a specific vulnerability.
Diff
diff --git a/code-library/latest/ug/neptune_example_neptune_DescribeDBClusters_section.md b/code-library/latest/ug/neptune_example_neptune_DescribeDBClusters_section.md index 3a427cc43..1eda4afbe 100644 --- a//code-library/latest/ug/neptune_example_neptune_DescribeDBClusters_section.md +++ b//code-library/latest/ug/neptune_example_neptune_DescribeDBClusters_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 `DescribeDBClusters`. +The following code examples show how to use `DescribeDBClusters`. @@ -73,0 +74,75 @@ 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 describe_db_clusters(neptune_client, cluster_id: str): + """ + Describes details of a Neptune DB cluster, paginating if needed. + + Args: + neptune_client (boto3.client): The Neptune client. + cluster_id (str): The ID of the cluster to describe. + + Raises: + ClientError: If there's an AWS API error (e.g., cluster not found). + """ + paginator = neptune_client.get_paginator('describe_db_clusters') + + try: + pages = paginator.paginate(DBClusterIdentifier=cluster_id) + + found = False + for page in pages: + for cluster in page.get('DBClusters', []): + found = True + print(f"Cluster Identifier: {cluster.get('DBClusterIdentifier')}") + print(f"Status: {cluster.get('Status')}") + print(f"Engine: {cluster.get('Engine')}") + print(f"Engine Version: {cluster.get('EngineVersion')}") + print(f"Endpoint: {cluster.get('Endpoint')}") + print(f"Reader Endpoint: {cluster.get('ReaderEndpoint')}") + print(f"Availability Zones: {cluster.get('AvailabilityZones')}") + print(f"Subnet Group: {cluster.get('DBSubnetGroup')}") + print("VPC Security Groups:") + for vpc_group in cluster.get('VpcSecurityGroups', []): + print(f" - {vpc_group.get('VpcSecurityGroupId')}") + print(f"Storage Encrypted: {cluster.get('StorageEncrypted')}") + print(f"IAM Auth Enabled: {cluster.get('IAMDatabaseAuthenticationEnabled')}") + print(f"Backup Retention Period: {cluster.get('BackupRetentionPeriod')} days") + print(f"Preferred Backup Window: {cluster.get('PreferredBackupWindow')}") + print(f"Preferred Maintenance Window: {cluster.get('PreferredMaintenanceWindow')}") + print("------") + + if not found: + # Treat empty response as cluster not found + raise ClientError( + {"Error": {"Code": "DBClusterNotFound", "Message": f"No cluster found with ID '{cluster_id}'"}}, + "DescribeDBClusters" + ) + + 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.") + elif code == "DBClusterNotFound": + print(f"Cluster '{cluster_id}' not found. Please verify the cluster ID.") + else: + print(f"Couldn't describe DB cluster. Here's why: {code}: {message}") + raise + + + + * For API details, see [DescribeDBClusters](https://docs.aws.amazon.com/goto/boto3/neptune-2014-10-31/DescribeDBClusters) in _AWS SDK for Python (Boto3) API Reference_. + + + +