Connecting to Neptune Using SPARQL and Node.js with Signature Version 4 Signing - Amazon Neptune
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Connecting to Neptune Using SPARQL and Node.js with Signature Version 4 Signing

Here is an example of how to connect to Neptune SPARQL using Node.js with Signature Version 4 authentication:

var AWS = require('aws-sdk'); var region = 'us-west-2'; // e.g. us-west-1 var neptune_endpoint = 'your-Neptune-cluster-endpoint'; // like: 'cluster-id.region.neptune.amazonaws.com' var query = `query=PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX class: <http://aws.amazon.com/neptune/csv2rdf/class/> PREFIX resource: <http://aws.amazon.com/neptune/csv2rdf/resource/> PREFIX prop: <http://aws.amazon.com/neptune/csv2rdf/datatypeProperty/> PREFIX objprop: <http://aws.amazon.com/neptune/csv2rdf/objectProperty/> SELECT ?movies ?title WHERE { ?jel prop:name "James Earl Jones" . ?movies ?p2 ?jel . ?movies prop:title ?title } LIMIT 10`; runQuery(query); function runQuery(q) { var endpoint = new AWS.Endpoint(neptune_endpoint); endpoint.port = 8182; var request = new AWS.HttpRequest(endpoint, region); request.path += 'sparql'; request.body = encodeURI(query); request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; request.headers['host'] = neptune_endpoint; request.method = 'POST'; var credentials = new AWS.CredentialProviderChain(); credentials.resolve((err, cred)=>{ var signer = new AWS.Signers.V4(request, 'neptune-db'); signer.addAuthorization(cred, new Date()); }); var client = new AWS.HttpClient(); client.handleRequest(request, null, function(response) { console.log(response.statusCode + ' ' + response.statusMessage); var responseBody = ''; response.on('data', function (chunk) { responseBody += chunk; }); response.on('end', function (chunk) { console.log('Response body: ' + responseBody); }); }, function(error) { console.log('Error: ' + error); }); }