如何使用版本4签名依赖项连接到Neptune

时间:2019-04-25 17:29:40

标签: gremlin amazon-neptune

我有一个EC2实例,可以使用Gremlin Console或通过插入this repository并运行maven命令来连接到gremlin。

但是,当我使用推荐的版本4签名依赖项时:

dependencies {
    compile(
            ...
            // neptune sigv4
            [group: "com.amazonaws", name:"aws-java-sdk-core", version: "1.11.307"],
            [group: "com.amazonaws", name:"amazon-neptune-sigv4-signer", version: "1.0"],
            [group: "com.amazonaws", name:"amazon-neptune-gremlin-java-sigv4", version: "1.0"],
            ...
    )
}

在非常相似的hello world程序中:

package com.test.neptune;

import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
import org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer;
import org.neo4j.cypher.internal.frontend.v2_3.repeat;

public class NeptuneExampleCopy {

    private static final String NEPTUNE_ENDPOINT = "my.endpoint.url";
    private static final int NEPTUNE_PORT = 0;

    public static void main(String[] args) {
            // connect to the neptune cluster
            final Cluster cluster = Cluster.build()
                    .addContactPoint(NEPTUNE_ENDPOINT)
                    .port(NEPTUNE_PORT)
                    .channelizer(SigV4WebSocketChannelizer.class)
                    .create();

            // run a traversal, print the results
            final Client client = cluster.connect();
            final ResultSet rs = client.submit("g.V().count()");
            for (Result r : rs) {
                    System.out.println(r);
            }

            // close the cluster
            cluster.close();
    }
}

Gradle引发以下异常:

Apr 25, 2019 5:24:21 PM io.netty.channel.ChannelInitializer exceptionCaught
WARNING: Failed to initialize a channel. Closing: [id: 0xd894eb28]
com.amazon.neptune.gremlin.driver.exception.SigV4PropertiesNotFoundException: Unable to load SigV4 properties from any of the providers
        at com.amazon.neptune.gremlin.driver.sigv4.ChainedSigV4PropertiesProvider.getSigV4Properties(ChainedSigV4PropertiesProvider.java:74)
        at com.amazon.neptune.gremlin.driver.sigv4.AwsSigV4ClientHandshaker.loadProperties(AwsSigV4ClientHandshaker.java:102)
        at com.amazon.neptune.gremlin.driver.sigv4.AwsSigV4ClientHandshaker.<init>(AwsSigV4ClientHandshaker.java:64)
        at org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer.createHandler(SigV4WebSocketChannelizer.java:210)
        at org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer.configure(SigV4WebSocketChannelizer.java:176)
        at org.apache.tinkerpop.gremlin.driver.Channelizer$AbstractChannelizer.initChannel(Channelizer.java:140)
        at org.apache.tinkerpop.gremlin.driver.Channelizer$AbstractChannelizer.initChannel(Channelizer.java:92)
        at io.netty.channel.ChannelInitializer.initChannel(ChannelInitializer.java:113)
        at io.netty.channel.ChannelInitializer.handlerAdded(ChannelInitializer.java:105)
        at io.netty.channel.DefaultChannelPipeline.callHandlerAdded0(DefaultChannelPipeline.java:617)
        at io.netty.channel.DefaultChannelPipeline.access$000(DefaultChannelPipeline.java:46)
        at io.netty.channel.DefaultChannelPipeline$PendingHandlerAddedTask.execute(DefaultChannelPipeline.java:1467)
        at io.netty.channel.DefaultChannelPipeline.callHandlerAddedForAllHandlers(DefaultChannelPipeline.java:1141)
        at io.netty.channel.DefaultChannelPipeline.invokeHandlerAddedIfNeeded(DefaultChannelPipeline.java:666)
        at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:510)
        at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:423)
        at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:482)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
        at java.lang.Thread.run(Thread.java:748)

Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
        at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:214)
        at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:198)
        at com.test.neptune.NeptuneExampleCopy.main(NeptuneExampleCopy.java:25)
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
        at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:310)
        at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:242)
        at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:212)
        ... 2 more
Caused by: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
        at org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient.chooseConnection(Client.java:499)
        at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:305)
        ... 4 more
Apr 25, 2019 5:24:22 PM io.netty.channel.ChannelInitializer exceptionCaught
WARNING: Failed to initialize a channel. Closing: [id: 0xc3ff34e0]
com.amazon.neptune.gremlin.driver.exception.SigV4PropertiesNotFoundException: Unable to load SigV4 properties from any of the providers
        at com.amazon.neptune.gremlin.driver.sigv4.ChainedSigV4PropertiesProvider.getSigV4Properties(ChainedSigV4PropertiesProvider.java:74)
        at com.amazon.neptune.gremlin.driver.sigv4.AwsSigV4ClientHandshaker.loadProperties(AwsSigV4ClientHandshaker.java:102)
        at com.amazon.neptune.gremlin.driver.sigv4.AwsSigV4ClientHandshaker.<init>(AwsSigV4ClientHandshaker.java:64)
        at org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer.createHandler(SigV4WebSocketChannelizer.java:210)
        at org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer.configure(SigV4WebSocketChannelizer.java:176)
        at org.apache.tinkerpop.gremlin.driver.Channelizer$AbstractChannelizer.initChannel(Channelizer.java:140)
        at org.apache.tinkerpop.gremlin.driver.Channelizer$AbstractChannelizer.initChannel(Channelizer.java:92)
        at io.netty.channel.ChannelInitializer.initChannel(ChannelInitializer.java:113)

该代码如何固定?是否有更好的Version 4签名依赖项?

1 个答案:

答案 0 :(得分:0)

SigV4处理程序尝试通过多个凭证提供程序获取您的AWS凭证。如果没有初始化凭证提供者,那么您一定会看到此异常。您如何初始化您的AWS凭证?您可以使用任何标准源,例如环境变量或JVM系统属性等。有关更多详细信息,请参见下面的文档:

https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-gremlin-java.html

更新:请确保您使用的是所有软件包和依赖项的最新版本。

例如:

// neptune sigv4 [group: "com.amazonaws", 
name:"aws-java-sdk-core", version: "1.11.542"], 

[group: "com.amazonaws", 
name:"amazon-neptune-sigv4-signer", version: "1.0.4"], 

[group: "com.amazonaws", 
name:"amazon-neptune-gremlin-java-sigv4", version: "1.0.5"], 

// for neptune [group: "org.apache.tinkerpop", 
name: "gremlin-driver", version: "3.4.1"]