Skip to content

Commit 9b50d02

Browse files
committed
added data examples
1 parent 88377b0 commit 9b50d02

File tree

7 files changed

+74
-70
lines changed

7 files changed

+74
-70
lines changed

.doc_gen/metadata/neptune_metadata.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ neptune_Hello:
1616
- neptune.java2.hello.main
1717
services:
1818
neptune: {DescribeDBClustersPaginator}
19+
neptune_ExecuteGremlinProfileQuery:
20+
languages:
21+
Java:
22+
versions:
23+
- sdk_version: 2
24+
github: javav2/example_code/neptune
25+
sdkguide:
26+
excerpts:
27+
- description:
28+
snippet_tags:
29+
- neptune.java2.data.query.gremlin.main
30+
services:
31+
neptune: {ExecuteGremlinProfileQuery}
32+
neptune_ExecuteGremlinQuery:
33+
languages:
34+
Java:
35+
versions:
36+
- sdk_version: 2
37+
github: javav2/example_code/neptune
38+
sdkguide:
39+
excerpts:
40+
- description:
41+
snippet_tags:
42+
- neptune.java2.data.query.gremlin.profile.main
43+
services:
44+
neptune: {ExecuteGremlinQuery}
1945
neptune_DeleteDBSubnetGroup:
2046
languages:
2147
Java:

javav2/example_code/neptune/src/main/java/com/example/neptune/analytics/CreateNeptuneGraphExample.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
44
import software.amazon.awssdk.regions.Region;
5-
import software.amazon.awssdk.services.neptunedata.NeptunedataClient;
65
import software.amazon.awssdk.services.neptunegraph.NeptuneGraphClient;
76
import software.amazon.awssdk.services.neptunegraph.model.CreateGraphRequest;
87
import software.amazon.awssdk.services.neptunegraph.model.CreateGraphResponse;
9-
import software.amazon.awssdk.services.neptunegraph.model.GraphStatus;
108
import software.amazon.awssdk.services.neptunegraph.model.NeptuneGraphException;
119

10+
/**
11+
* This Java example demonstrates how to query Amazon Neptune Analytics (Neptune Graph) using the AWS SDK for Java V2.
12+
*
13+
* VPC NETWORKING REQUIREMENT:
14+
* ----------------------------------------------------------------------
15+
* Amazon Neptune Analytics must be accessed from within an Amazon VPC. This means:
16+
*
17+
* 1. Your application must run within a VPC environment such as EC2, Lambda, ECS, Cloud9, or an AWS managed notebook.
18+
* 2. You **cannot run this code from your local machine** unless you are connected via a VPN or Direct Connect.
19+
* 3. Ensure that your Neptune Graph cluster endpoint is accessible and security groups allow inbound access from your client.
20+
* 4. Always use the HTTPS endpoint when setting the `endpointOverride()` value.
21+
*
22+
* You can test access by running:
23+
* curl https://<graph-endpoint>:8182/status
24+
* ----------------------------------------------------------------------
25+
*/
26+
1227
public class CreateNeptuneGraphExample {
1328

1429
public static void main(String[] args) {
15-
// Set the desired region
1630
Region region = Region.US_EAST_1;
17-
18-
// Set the name for your new graph
1931
String graphName = "sample-analytics-graph";
2032

2133
// Create the NeptuneGraph client
@@ -25,7 +37,6 @@ public static void main(String[] args) {
2537
.build();
2638

2739
executeCreateGraph(client, graphName);
28-
2940
}
3041

3142
/**

javav2/example_code/neptune/src/main/java/com/example/neptune/data/GremlinProfileQueryExample.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
import software.amazon.awssdk.http.apache.ApacheHttpClient;
99
import software.amazon.awssdk.regions.Region;
1010
import software.amazon.awssdk.services.neptunedata.NeptunedataClient;
11-
12-
1311
import software.amazon.awssdk.services.neptunedata.model.ExecuteGremlinProfileQueryRequest;
1412
import software.amazon.awssdk.services.neptunedata.model.ExecuteGremlinProfileQueryResponse;
1513
import software.amazon.awssdk.services.neptunedata.model.NeptunedataException;
16-
1714
import java.net.URI;
1815
import java.time.Duration;
1916

@@ -25,17 +22,14 @@
2522
* ----------------------------------------------------------------------------------
2623
* Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster.
2724
* It does not expose a public endpoint, so this code must be executed from:
28-
* - An EC2 instance, Lambda function, ECS task, Cloud9 IDE, or
29-
* - A connected environment (VPN, Direct Connect, or peered VPC).
25+
*
26+
* - An **AWS Lambda function** configured to run inside the same VPC
27+
* - An **EC2 instance** or **ECS task** running in the same VPC
28+
* - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC**
3029
*
3130
* To see an example, see Creating an AWS Lambda function that queries Neptune graph data within the VPC
3231
* in the AWS Code Library.
3332
*
34-
* Notes:
35-
* - Ensure Neptune's security group allows inbound traffic on port 8182.
36-
* - Replace the endpoint below with your Neptune cluster's HTTPS endpoint.
37-
* - To verify access, run: curl https://<your-neptune-endpoint>:8182/status
38-
* ----------------------------------------------------------------------------------
3933
*/
4034
public class GremlinProfileQueryExample {
4135

@@ -67,6 +61,7 @@ public static void main(String[] args) {
6761
}
6862
}
6963

64+
// snippet-start:[neptune.java2.data.query.gremlin.profile.main]
7065
/**
7166
* Executes a Gremlin PROFILE query using the provided NeptunedataClient.
7267
*
@@ -87,4 +82,5 @@ private static void executeGremlinProfileQuery(NeptunedataClient client) {
8782
System.out.println("No output returned from the profile query.");
8883
}
8984
}
85+
// snippet-end:[neptune.java2.data.query.gremlin.profile.main]
9086
}

javav2/example_code/neptune/src/main/java/com/example/neptune/data/NeptuneGremlinExplainAndProfileExample.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,18 @@
2121
*
2222
* VPC NETWORKING REQUIREMENT:
2323
* ----------------------------------------------------------------------
24-
* Amazon Neptune is designed to be **accessed from within an Amazon VPC**.
25-
* It does not expose a public endpoint. This means:
24+
* Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster.
25+
* It does not expose a public endpoint, so this code must be executed from:
2626
*
27-
* 1. Your Java application must run **within the same VPC** (e.g., via an EC2 instance, Lambda function, ECS task,
28-
* or AWS Cloud9 environment), or from a peered VPC that has network access to Neptune.
29-
*
30-
* 2. You cannot run this example directly from your local machine (e.g., via IntelliJ or PyCharm on your laptop)
31-
* unless you set up a VPN or AWS Direct Connect that bridges your local environment to your VPC.
32-
*
33-
* 3. You must ensure the **VPC Security Group** attached to your Neptune cluster allows **inbound access on port 8182**
34-
* from the instance or environment where this Java code runs.
35-
*
36-
* 4. The `endpointOverride()` must use the **HTTPS Neptune endpoint** including the `:8182` port.
27+
* - An **AWS Lambda function** configured to run inside the same VPC
28+
* - An **EC2 instance** or **ECS task** running in the same VPC
29+
* - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC**
3730
*
3831
* To see an example, see Creating an AWS Lambda function that queries Neptune graph data within the VPC
3932
* in the AWS Code Library.
4033
*
41-
* TIP:
42-
* You can test connectivity using `curl` or `telnet` from your instance to:
43-
* curl https://<neptune-endpoint>:8182/status
44-
* If this fails, it’s likely a networking or security group issue.
45-
*
46-
* ----------------------------------------------------------------------
4734
*/
4835
public class NeptuneGremlinExplainAndProfileExample {
49-
5036
// Specify the endpoint. You can obtain an endpoint by running
5137
// the main scenario.
5238
private static final String NEPTUNE_ENDPOINT = "https://[Specify-Your-Endpoint]:8182";
@@ -63,7 +49,7 @@ public static void main(String[] args) {
6349
.build())
6450
.build();
6551

66-
executeGremlinExplainQuery(NeptunedataClient client)
52+
executeGremlinExplainQuery(client);
6753
}
6854

6955
/**

javav2/example_code/neptune/src/main/java/com/example/neptune/data/NeptuneGremlinQueryExample.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,16 @@
1818
*
1919
* VPC NETWORKING REQUIREMENT:
2020
* ----------------------------------------------------------------------
21-
* Amazon Neptune is designed to be **accessed from within an Amazon VPC**.
22-
* It does not expose a public endpoint. This means:
21+
* Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster.
22+
* It does not expose a public endpoint, so this code must be executed from:
2323
*
24-
* 1. Your Java application must run **within the same VPC** (e.g., via an EC2 instance, Lambda function, ECS task,
25-
* or AWS Cloud9 environment), or from a peered VPC that has network access to Neptune.
26-
*
27-
* 2. You cannot run this example directly from your local machine (e.g., via IntelliJ or PyCharm on your laptop)
28-
* unless you set up a VPN or AWS Direct Connect that bridges your local environment to your VPC.
29-
*
30-
* 3. You must ensure the **VPC Security Group** attached to your Neptune cluster allows **inbound access on port 8182**
31-
* from the instance or environment where this Java code runs.
32-
*
33-
* 4. The `endpointOverride()` must use the **HTTPS Neptune endpoint** including the `:8182` port.
24+
* - An **AWS Lambda function** configured to run inside the same VPC
25+
* - An **EC2 instance** or **ECS task** running in the same VPC
26+
* - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC**
3427
*
3528
* To see an example, see Creating an AWS Lambda function that queries Neptune graph data within the VPC
3629
* in the AWS Code Library.
3730
*
38-
* TIP:
39-
* You can test connectivity using `curl` or `telnet` from your instance to:
40-
* curl https://<neptune-endpoint>:8182/status
41-
* If this fails, it’s likely a networking or security group issue.
42-
*
43-
* ----------------------------------------------------------------------
4431
*/
4532

4633
public class NeptuneGremlinQueryExample {
@@ -62,6 +49,7 @@ public static void main(String[] args) {
6249
.build();
6350
}
6451

52+
// snippet-start:[neptune.java2.data.query.gremlin.main]
6553
/**
6654
* Executes a Gremlin query against an Amazon Neptune database using the provided {@link NeptunedataClient}.
6755
*
@@ -94,4 +82,5 @@ public static void executeGremlinQuery(NeptunedataClient client) {
9482
client.close();
9583
}
9684
}
85+
// snippet-end:[neptune.java2.data.query.gremlin.main]
9786
}

javav2/example_code/neptune/src/main/java/com/example/neptune/data/OpenCypherExplainExample.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,16 @@
2020
* ------------------------------------------------------------------------------
2121
* VPC NETWORKING REQUIREMENT:
2222
* ------------------------------------------------------------------------------
23-
* Amazon Neptune must be accessed from within an Amazon VPC. It does not expose
24-
* a public endpoint.
23+
* Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster.
24+
* It does not expose a public endpoint, so this code must be executed from:
2525
*
26-
* 1. This Java application must run from an environment inside the same VPC as the Neptune cluster,
27-
* such as EC2, ECS, AWS Lambda, AWS Cloud9, or a connected network via VPN or Direct Connect.
28-
*
29-
* 2. Ensure the Neptune cluster’s security group allows inbound access on port 8182 from the host
30-
* running this application.
31-
*
32-
* 3. Use the Neptune HTTPS endpoint with port 8182 in `endpointOverride()`.
26+
* - An **AWS Lambda function** configured to run inside the same VPC
27+
* - An **EC2 instance** or **ECS task** running in the same VPC
28+
* - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC**
3329
*
3430
* To see an example, see Creating an AWS Lambda function that queries Neptune graph data within the VPC
35-
* in the AWS Code Library. *
31+
* in the AWS Code Library.
3632
*
37-
* Test connectivity with:
38-
* curl https://<your-neptune-endpoint>:8182/status
39-
* ------------------------------------------------------------------------------
4033
*/
4134
public class OpenCypherExplainExample {
4235

@@ -57,6 +50,7 @@ public static void main(String[] args) {
5750
executeGremlinQuery(client);
5851
}
5952

53+
// snippet-start:[neptune.java2.data.query.opencypher.main]
6054
/**
6155
* Executes an OpenCypher EXPLAIN query using the provided Neptune data client.
6256
*
@@ -87,4 +81,5 @@ public static void executeGremlinQuery(NeptunedataClient client) {
8781
client.close();
8882
}
8983
}
84+
// snippet-end:[neptune.java2.data.query.opencypher.main]
9085
}

javav2/usecases/creating_neptune_lambda/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
This guide provides a step-by-step walkthrough for creating and deploying an AWS Lambda function that queries an Amazon Neptune graph database using the Neptune Data API.
1212

13-
Amazon Neptune is a fully managed graph database service designed to operate within a Virtual Private Cloud (VPC). Because of this, any Lambda function that needs to access Neptune must also run inside the same VPC and be granted appropriate network and IAM permissions—external access is not supported.
13+
Amazon Neptune is a fully managed graph database service designed to operate within a Virtual Private Cloud (VPC). Because of this, any Lambda function that needs to access Neptune must also run inside the same VPC and be granted appropriate network and IAM permissions. External access is not supported.
1414

1515
To ensure secure and reliable communication between Lambda and Neptune, you’ll configure key AWS infrastructure components, including VPC subnets, security groups, and IAM roles. This guide covers all necessary setup and configuration tasks to help you successfully connect your Lambda function to Neptune using the Neptune Data API.
1616

@@ -19,6 +19,7 @@ To ensure secure and reliable communication between Lambda and Neptune, you’ll
1919

2020
#### Topics
2121
+ Prerequisites
22+
+ Set Up the Amazon Neptune Cluster and VPC
2223
+ Create an AWS Identity and Access Management (IAM) role that is used to execute Lambda functions
2324
+ Create an IntelliJ project
2425
+ Add the POM dependencies to your project
@@ -39,13 +40,13 @@ To follow along with this tutorial, you need the following:
3940
### Important
4041

4142
+ The AWS services included in this document are included in the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc).
42-
+ This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
43+
+ This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
4344
+ Running this code might result in charges to your AWS account.
4445
+ Be sure to delete all of the resources that you create during this tutorial so that you won't be charged.
4546

4647
## Set Up the Amazon Neptune Cluster and VPC
4748

48-
Amazon Neptune requires a VPC (Virtual Private Cloud) with at least two subnets in different Availability Zones (AZs) to ensure high availability and fault tolerance.
49+
Amazon Neptune requires a VPC with at least two subnets in different Availability Zones (AZs) to ensure high availability and fault tolerance.
4950

5051
If you're unsure which VPC or subnets to use, you can easily generate the required resources by running the Amazon Neptune Basics scenario from the AWS Code Library. This setup will provision:
5152

0 commit comments

Comments
 (0)