Some of these resources are not free-tier resources. For pricing information, see
Amazon Neptune Pricing and Amazon EC2 Pricing. You can delete the
stack when you are finished with it to stop any charges.

This AWS CloudFormation stack is intended as a basis for a tutorial for Amazon Neptune.
We recommend you to
use stricter IAM policies and security for your production environment if you use
this
template. For information on securing resources, see Amazon VPC Security
and Amazon EC2 Network and
Security.

The following permissions are only required to delete a stack: iam:DeleteRole,
iam:RemoveRoleFromInstanceProfile,
iam:DeleteRolePolicy, iam:DeleteInstanceProfile, and
ec2:DeleteVpcEndpoints.

Also note that ec2:*Vpc grants ec2:DeleteVpc
permissions.

EC2 Key Pair

You must have a key pair (and the PEM file) available in the Region that you
create the AWS CloudFormation stack in. If you need to create a key pair, see
Creating a Key Pair Using Amazon EC2 for instructions on creating the
pair and downloading the PEM file.

Launch the Amazon Neptune CloudFormation Stack

To launch the Neptune stack in the AWS CloudFormation console, choose one of the Launch
Stack buttons in the following table.

On the Specify Details page, choose a key pair for the
EC2SSHKeyPairName.

This key pair is required to access the EC2 instance. Ensure that you have the PEM
file
for the key pair that you choose.

Choose Next.

On the Options page, choose
Next.

On the Review page, select the check box to acknowledge that AWS CloudFormation
will create IAM resources. Then choose Create.

Accessing the Neptune Graph

Now that you have an instance, you can log into your EC2 instance using SSH and connect
to the
Neptune graph. For information about connecting to an EC2 instance using SSH, see
Connect to Your Linux
Instance in the Amazon EC2 User Guide for Linux Instances.

If you are using a Linux or macOS command line to connect to the EC2 instance, you
can paste
the SSH command from the SSHAccess item in the
Outputs section of the AWS CloudFormation stack. This requires that you have
the PEM file in the current directory and the PEM file permissions must be set
to 400
(chmod 400 keypair.pem).

After you are connected, see the following sections, which contain information about
using
the Gremlin and SPARQL endpoints of Neptune.

The following tutorial walks you through using Gremlin with Amazon Neptune,
including how to add vertices, edges, properties, and more, while highlighting
Neptune-specific Gremlin implementation differences.

The Gremlin Console sends a separate command at every newline ('\n'), so
they will each be a separate transaction in that case. This example has
all the commands on separate lines for readability. Remove the newline
('\n') characters to send it as a single command via
the Gremlin Console.

All statements other than the last statement must end in a terminating step, such
as
.next() or .iterate(), or they will not run.
The Gremlin Console does not require these terminating steps.

All statements that are sent together are included in a single transaction and succeed
or
fail together.

RDF / SPARQL

SPARQL is a query language for the Resource Description Framework (RDF), which is
a graph data format designed for the web. Amazon Neptune is compatible with SPARQL
1.1. This means that you can connect to a Neptune DB instance and query the graph
using the
query language described in the SPARQL 1.1 Query Language specification.

A query in SPARQL consists of a SELECT clause to specify the
variables to return and a WHERE clause to specify which data to match
in the graph. If you are unfamiliar with SPARQL queries, see Writing Simple
Queries in the SPARQL
1.1 Query Language.

The HTTP endpoint for SPARQL queries to a Neptune DB instance is
http://your-neptune-endpoint:8182/sparql.

To connect to SPARQL

You can get the SPARQL endpoint for your Neptune cluster from the
SparqlEndpoint item in the
Outputs section of the AWS CloudFormation stack.

Type the following to submit a SPARQL UPDATE using HTTP POST and the
curl command.

The preceding example returns up to 10 of the triples
(subject-predicate-object) in the graph by using the ?s ?p ?o
query with a limit of 10. To query for something else, replace it with
another SPARQL query.

Note

The default MIME type of a response is
application/sparql-results+json for SELECT
and ASK queries.

The default MIME type of a response is
application/n-quads for CONSTRUCT and
DESCRIBE queries.