Connecting to Amazon Neptune databases using IAM authentication with Java and SPARQL
This section shows how to connect to Neptune using either RDF4J or Apache Jena with Signature Version 4 authentication.
Prerequisites
Java 8 or higher.
Apache Maven 3.3 or higher.
For information about installing these prerequisites on an EC2 instance running Amazon Linux, see Prerequisites for connecting Amazon Neptune databases using IAM authentication.
-
IAM credentials to sign the requests. For more information, see Using the Default Credential Provider Chain
in the Amazon SDK for Java Developer Guide. Note
If you are using temporary credentials, they expire after a specified interval, including the session token.
You must update your session token when you request new credentials. For more information, see Using Temporary Security Credentials to Request Access to Amazon Resources
in the IAM User Guide. -
Set the
SERVICE_REGIONvariable to one of the following, indicating the Region of your Neptune DB instance:US East (N. Virginia):
us-east-1US East (Ohio):
us-east-2US West (N. California):
us-west-1US West (Oregon):
us-west-2Canada (Central):
ca-central-1Canada West (Calgary):
ca-west-1South America (São Paulo):
sa-east-1Europe (Stockholm):
eu-north-1Europe (Spain):
eu-south-2Europe (Ireland):
eu-west-1Europe (London):
eu-west-2Europe (Paris):
eu-west-3Europe (Frankfurt):
eu-central-1Middle East (Bahrain):
me-south-1Middle East (UAE):
me-central-1Israel (Tel Aviv):
il-central-1Africa (Cape Town):
af-south-1Asia Pacific (Hong Kong):
ap-east-1Asia Pacific (Tokyo):
ap-northeast-1Asia Pacific (Seoul):
ap-northeast-2Asia Pacific (Osaka):
ap-northeast-3Asia Pacific (Singapore):
ap-southeast-1Asia Pacific (Sydney):
ap-southeast-2Asia Pacific (Jakarta):
ap-southeast-3Asia Pacific (Melbourne):
ap-southeast-4Asia Pacific (Malaysia):
ap-southeast-5Asia Pacific (Mumbai):
ap-south-1China (Beijing):
cn-north-1China (Ningxia):
cn-northwest-1Amazon GovCloud (US-West):
us-gov-west-1Amazon GovCloud (US-East):
us-gov-east-1
To connect to Neptune using either RDF4J or Apache Jena with Signature Version 4 signing
-
Clone the sample repository from GitHub.
git clone https://github.com/aws/amazon-neptune-sparql-java-sigv4.git -
Change into the cloned directory.
cd amazon-neptune-sparql-java-sigv4 -
Get the latest version of the project by checking out the branch with the latest tag.
git checkout $(git describe --tags `git rev-list --tags --max-count=1`) -
Enter one of the following commands to compile and run the example code.
Replace
your-neptune-endpointwith the hostname or IP address of your Neptune DB instance. The default port is 8182.Note
For information about finding the hostname of your Neptune DB instance, see the Connecting to Amazon Neptune Endpoints section.
Eclipse RDF4J
Enter the following to run the RDF4J example.
mvn compile exec:java \ -Dexec.mainClass="com.amazonaws.neptune.client.rdf4j.NeptuneRdf4JSigV4Example" \ -Dexec.args="https://your-neptune-endpoint:port"Apache Jena
Enter the following to run the Apache Jena example.
mvn compile exec:java \ -Dexec.mainClass="com.amazonaws.neptune.client.jena.NeptuneJenaSigV4Example" \ -Dexec.args="https://your-neptune-endpoint:port" To view the source code for the example, see the examples in the
src/main/java/com/amazonaws/neptune/client/directory.
To use the SigV4 signing driver in your own Java application, add the
amazon-neptune-sigv4-signer Maven package to the <dependencies>
section of your pom.xml. We recommend that you use the examples as a starting
point.