Getting getaddrinfo ENOTFOUND when trying to connect to my AWS Neptune with node.js and gremlin

Viewed 376

I am trying to connect to my Amazon Neptune instance from a API GW. I am using Node.js and Lambda

My YML looks like this

  NeptuneDBCluster:
    Type: "AWS::Neptune::DBCluster"

Outputs:
  NeptuneEndpointAddress:
    Description: Neptune DB endpoint address
    Value: !GetAtt NeptuneDBCluster.Endpoint
    Export:
      Name: !Sub ${env:STAGE}-neptune-endpoint-address

My code looks like this

const gremlin = require('gremlin');
const {
    NEPTUNE_ENDPOINT
} = process.env;
const { cardinality: { single } } = gremlin.process;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;

async function createUserNode(event, context, callback) {
    const url = 'wss://" + NEPTUNE_ENDPOINT + ":8182/gremlin';
    const dc = new DriverRemoteConnection(url);

    const parsedBody = JSON.parse(event.body);


    try {
        const graph = new Graph();
        const g = graph.traversal().withRemote(dc);

        const vertex = await g.addV(parsedBody.type)
            .property(single, 'name', parsedBody.name)
            .property(single, 'username', parsedBody.username)
            .property('age', parsedBody.age)
            .property('purpose', parsedBody.purpose)
            .next();

        if (vertex.value) {
            return callback(null, {
                statusCode: 200,
                body: vertex.value
            });
        }

    } catch (error) {
        console.error(error);
    }

};

I keep getting the folowing error from Cloudwatch (I also tried creating a local js file and it gives the same error)

ERROR   Error: getaddrinfo ENOTFOUND my-url
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'my-url'
}

I also tried to write the endpoint without getting it from process.env and I am still facing the same issue. What am i missing?

1 Answers

Alright for anyone being as confused as I am when trying Neptune for first time. You need to create a database instance aswell, I thought the Serverless Framework would do this to me but now I know.

Related