Amazon Neptune - Hands On Demo

Create an Amazon Neptune Cluster

 

  1. Open Amazon Neptune Console: In the AWS Management Console, find and select Amazon Neptune.

  2. Launch a New Database: Click on "Create Database." Fill in the necessary details:

    • Type: Serverless
    • Engine version: Neptune 1.3.0.0.R1
    • Templates: Development and testing
    • DB Cluster name: db-neptune-1
    • Capacity section:
      • Minimum Neptune capacity unit (NCUs): 1
      • Maximum Neptune capacity unit (NCUs): 2.5
    • Availability and Durability:
      • Multi-AZ deployment: No
    • Network and security:
      • Virtual Private Cloud (VPC): Default
      • Subnet group: rds-ec2-db-subnet-group-1
      • VPC security groups: default
    • Notebook configuration: Uncheck Create notebook
  3. Keep rest all values as default.

Create an Amazon EC2 Machine to connect as Gremlin Client

 

  1. Open the Amazon EC2 Console.

  2. Launch Instance: From the dashboard, select "Launch instance".

  3. Name Your Instance: Enter a descriptive name under "Name and tags".

  4. Select OS Image:

    1. Choose "Quick Start" and select "Amazon Linux" or "AL2023" for the operating system.
    2. Pick an HVM version of Amazon Linux 2, marked "Free Tier eligible".
  5. Choose Instance Type:

    1. Select t2.micro (default) or t3.micro in regions where t2.micro is unavailable, both eligible for the Free Tier.
  6. Configure Key Pair:

    1. Select a key pair you've created earlier. Avoid launching without a key pair to ensure you can connect to your instance.
  7. Network Settings:

    1. Click "Edit" next to Network settings. Use the wizard's suggested security group or select an existing one from your setup.
  8. Launch:

    1. Review your instance configuration and click "Launch instance".
    2. Post-launch, select "View all instances" to monitor your instance's status, which transitions from "pending" to "running" and receives a public DNS name.

To connect to your instance using the browser-based client from the Amazon EC2 console

  1. Open the Amazon EC2 console.

  2. In the navigation pane, choose Instances.

  3. Select the instance and choose Connect.

  4. Choose EC2 Instance Connect.

  5. Verify the user name and choose Connect to open a terminal window.

sudo yum install java-11-amazon-corretto-devel
sudo /usr/sbin/alternatives --config java
wget https://archive.apache.org/dist/tinkerpop/3.6.5/apache-tinkerpop-gremlin-console-3.6.5-bin.zip
unzip apache-tinkerpop-gremlin-console-3.6.5-bin.zip
cd apache-tinkerpop-gremlin-console-3.6.5
cat > conf/neptune-remote.yaml << EOF
hosts: [$NEPTUNE_ENDPOINT]
port: 8182
connectionPool: { enableSsl: true }
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
              config: { serializeResultToString: true }}
EOF

In the conf subdirectory of the extracted directory, create a file named neptune-remote.yaml with the following text. Replace your-neptune-endpoint

Change directories into the unzipped directory.

Unzip the Gremlin Console zip file.

Download the appropriate version of the Gremlin console from the Apache web site.

Enter the following to set Java 11 as the default runtime on your EC2 instance.

Install Java. If you're using Amazon Linux 2023 (AL2023).

export NEPTUNE_ENDPOINT=example-neptune-endpoint
bin/gremlin.sh
:remote connect tinkerpop.server conf/neptune-remote.yaml
:remote console
g.V().limit(1)
g.addV('person').property('name', 'justin')
g.addV('person').property(id, '1').property('name', 'martin')
g.V('1').property(single, 'name', 'marko')

Add a vertex with custom id.

Add vertex with label and property.

Enter the following to send a query to the Gremlin Graph.

At the gremlin> prompt, enter the following to switch to remote mode. This sends all Gremlin queries to the remote connection.

 

 

At the gremlin> prompt, enter the following to connect to the Neptune DB instance.

Enter the following command to run the Gremlin Console.

Change property or add property if it doesn't exist.

g.V('1').property('age', 29)
g.addV('person').property(id, '2').property('name', 'vadas').property('age', 27).iterate()
g.addV('software').property(id, '3').property('name', 'lop').property('lang', 'java').iterate()
g.addV('person').property(id, '4').property('name', 'josh').property('age', 32).iterate()
g.addV('software').property(id, '5').property('name', 'ripple').property('lang', 'java').iterate()
g.addV('person').property(id, '6').property('name', 'peter').property('age', 35)
g.V('1').addE('knows').to(__.V('2')).property('weight', 0.5).iterate()
g.addE('knows').from(__.V('1')).to(__.V('4')).property('weight', 1.0) 
g.V('1').addE('created').to(__.V('3')).property('weight', 0.4).iterate()
g.V('4').addE('created').to(__.V('5')).property('weight', 1.0).iterate()
g.V('4').addE('knows').to(__.V('3')).property('weight', 0.4).iterate()
g.V('6').addE('created').to(__.V('3')).property('weight', 0.2)

Add property, but append property if property already has a value.

Add multiple vertices.

Add edges.

Add the rest of the Modern graph.

Delete a vertex.

g.V().has('name', 'justin').drop()
g.V().hasLabel('person')
g.V().has('name', 'marko').out('knows').valueMap()
g.addV("Label1::Label2::Label3")
g.V().property(single, 'lastUpdate', datetime('2018-01-01T00:00:00'))

Run a traversal.

Run a Traversal with values (valueMap()).

Specify multiple labels.

Specify Time/date.

Delete vertices, properties, or edges.

g.V().hasLabel('person').properties('age').drop().iterate()
g.V('1').drop().iterate()
g.V().outE().hasLabel('created').drop()

When you are finished, enter the following to exit the Gremlin Console.

 

 

:exit

Clean Up

  1. Delete the EC2 Instance.
  2. Delete the Amazon Neptune Instance and Database.

Thanks

For

Watching

Amazon Neptune - Hands On Demo

By Deepak Dubey

Amazon Neptune - Hands On Demo

Amazon Neptune - Hands On Demo

  • 64