Connect to AWS Neptune with Golang GremlinGo

huangapple go评论92阅读模式
英文:

Connect to AWS Neptune with Golang GremlinGo

问题

我目前正在尝试通过Go语言与AWS Neptune建立连接,但是无法成功。我可以连接到AWS本身,但是当我尝试连接到Neptune数据库时,它显示"无法建立成功的连接:dial tcp 172.31.4.48:8182: i/o timeout"。我正在使用Gremlingo模块,就像这段代码中一样:

package main

import (
	"fmt"
	"net/http"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/neptune"
	"github.com/gin-gonic/gin"

	gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

func main() {

	sess, err := session.NewSession(&aws.Config{
		Region:      aws.String("us-east-id1"),
		Credentials: credentials.NewStaticCredentials("AWS-id key", "aws secret id key", ""),
	})

	if err != nil {
		fmt.Println("Couldn't create new session")
		return
	}

	neptune.New(sess)

	driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("wss://database-1-instance-1.asdasdasd.us-east-1.neptune.amazonaws.com:8182/gremlin",
		func(settings *gremlingo.DriverRemoteConnectionSettings) {
			settings.TraversalSource = "g"
		})

	if err != nil {
		fmt.Println(err)
		return
	}

	//Cleanup
	defer driverRemoteConnection.Close()

	//Creating graph traversal
	g := gremlingo.Traversal().WithRemote(driverRemoteConnection)

	// Perform traversal
	results, err := g.V().Limit(2).ToList()
	if err != nil {
		fmt.Println(err)
		return
	}

	// print results
	for _, r := range results {
		fmt.Println(r.GetString())
	}
}

我不太确定问题出在哪里,所以我尝试连接到集群本身,由于连接不成功,我尝试连接到Writer。非常感谢您的帮助。

最好的祝福。

英文:

I am at the moment trying to set up a connection to AWS Neptune via go, but its not working. I am able to connect to AWS itself, but when I try to connect to Neptune DB it says "no successful connections could be made: dial tcp 172.31.4.48:8182: i/o timeout". I am using the Gremlingo module like in this code

package main

import (
	"fmt"
	"net/http"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/neptune"
	"github.com/gin-gonic/gin"

	gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

func main() {

	sess, err := session.NewSession(&aws.Config{
		Region:      aws.String("us-east-id1"),
		Credentials: credentials.NewStaticCredentials("AWS-id key", "aws secret id key", ""),
	})

	if err != nil {
		fmt.Println("Couldn't create new session")
		return
	}

	neptune.New(sess)

	driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("wss://database-1-instance-1.asdasdasd.us-east-1.neptune.amazonaws.com:8182/gremlin",
		func(settings *gremlingo.DriverRemoteConnectionSettings) {
			settings.TraversalSource = "g"
		})

	if err != nil {
		fmt.Println(err)
		return
	}

	//Cleanup
	defer driverRemoteConnection.Close()

	//Creating graph traversal
	g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

	// Perform traversal
	results, err := g.V().Limit(2).ToList()
	if err != nil {
		fmt.Println(err)
		return
	}

	// print results
	for _, r := range results {
		fmt.Println(r.GetString())
	}
}

I wasn't quite sure what the problem was so I tried to connect to the cluster itself and as it didn't work I tried to connect to the Writer.
Thank you very much for your help.

Best regards

答案1

得分: 1

亚马逊海王星运行在一个虚拟私有云(VPC)中,并且不提供公共终端节点。设计用于发送查询的代码必须具有对该VPC的访问权限。这可以简单地通过在同一VPC中运行的EC2实例上运行代码来实现,但还有许多其他授予对VPC访问权限的方式,例如负载均衡器、VPC对等连接、直连等等。

检查代码是否可以访问数据库的一种简单方法是从相同的源点发送一个HTTP请求到/status API,并查看是否正常工作。

英文:

Amazon Neptune runs inside of a VPC and does not expose a public endpoint. Code designed to send queries must have access tho that VPC. This could be as simple as the code running on an EC2 instance in the same VPC, but there are many other ways that access to a VPC can be granted, such as Load Balancers, VPC Peering, Direct Connect, and many others.

An easy way to check if your code can access the database, is to send an HTTP request to the /status API from the same point of origin and see if it works.

答案2

得分: 0

我使用了另一个客户端库,像"grammes"这样的,它工作得很好,但是"gremlingo"失败了。

点击这里查看图片

英文:

i use another client lib like "grammes", its worked well, but "gremlingo" failed.

enter image description here

huangapple
  • 本文由 发表于 2023年2月20日 02:07:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75502340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定