AWS code-library documentation change
Summary
Added Python code example for ExecuteGremlinQuery with VPC access requirements documentation and error handling
Security assessment
Added documentation emphasizes VPC isolation requirements for Neptune access (no public endpoints), which is a security best practice. However, this appears to be standard security guidance rather than addressing a specific vulnerability.
Diff
diff --git a/code-library/latest/ug/neptune_example_neptune_ExecuteGremlinQuery_section.md b/code-library/latest/ug/neptune_example_neptune_ExecuteGremlinQuery_section.md index c2de627df..df4f07d83 100644 --- a//code-library/latest/ug/neptune_example_neptune_ExecuteGremlinQuery_section.md +++ b//code-library/latest/ug/neptune_example_neptune_ExecuteGremlinQuery_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 `ExecuteGremlinQuery`. +The following code examples show how to use `ExecuteGremlinQuery`. @@ -49,0 +50,80 @@ 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). + + + """ + Running this example. + + ---------------------------------------------------------------------------------- + VPC Networking Requirement: + ---------------------------------------------------------------------------------- + Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster. + It does not expose a public endpoint, so this code must be executed from: + + - An **AWS Lambda function** configured to run inside the same VPC + - An **EC2 instance** or **ECS task** running in the same VPC + - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC** + + """ + + # Replace with your actual Neptune endpoint + NEPTUNE_ENDPOINT = "https://[Specify-Your-Endpoint]:8182" + + def main(): + """ + Entry point of the program. Initializes the Neptune client and runs both EXPLAIN and PROFILE queries. + """ + config = Config(connect_timeout=10, read_timeout=30, retries={'max_attempts': 3}) + + neptune_client = boto3.client( + "neptunedata", + endpoint_url=NEPTUNE_ENDPOINT, + config=config + ) + + try: + run_profile_query(neptune_client) + except ClientError as e: + print(f"Neptune error: {e.response['Error']['Message']}") + except BotoCoreError as e: + print(f"BotoCore error: {str(e)}") + except Exception as e: + print(f"Unexpected error: {str(e)}") + + def run_profile_query(neptune_client): + """ + Runs a PROFILE query on the Neptune graph database. + """ + print("Running Gremlin PROFILE query...") + + try: + response = neptune_client.execute_gremlin_profile_query( + gremlinQuery="g.V().has('code', 'ANC')" + ) + print("Profile Query Result:") + output = response.get("output") + if output: + print(output.read().decode('utf-8')) + else: + print("No explain output returned.") + except Exception as e: + print(f"Failed to execute PROFILE query: {str(e)}") + + + if __name__ == "__main__": + main() + + + + * For API details, see [ExecuteGremlinQuery](https://docs.aws.amazon.com/goto/boto3/neptune-2014-10-31/ExecuteGremlinQuery) in _AWS SDK for Python (Boto3) API Reference_. + + + +