简体   繁体   English

Amazon AWS S3的GO脚本运行时错误

[英]GO script runtime error for Amazon AWS S3

I'm currently attempting to run the following Golang build for the first time on a Amazon Linux Distro: 我目前正在尝试在Amazon Linux Distro上首次运行以下Golang构建:

https://github.com/adammck/s3-graphite https://github.com/adammck/s3-graphite

README Here: 自述文件在这里:

go get github.com/adammck/s3-graphite
cd $GOPATH/adammck/s3-graphite
go build

After this, I set my variables in my .bashrc file like below: 之后,我在.bashrc文件中设置变量,如下所示:

# AWS keys with read access to the bucket
export AWS_ACCESS_KEY_ID=xxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=yyyyyyyyyy
export AWS_REGION=us-east-1

# the bucket to watch
export S3_BUCKET=my-bucket
export S3_PREFIX=dir/subdir

# the server to send metrics to
export GRAPHITE_ADDRESS=metrics.example.com
export GRAPHITE_PREFIX=s3-count.my-bucket.dir.subdir

I set my GOPATH to the following: 我将GOPATH设置为以下内容:

export GOPATH="$HOME/work/"

I cd into the dir to run a go build which works like it should, but when I go to run the following after the go build: 我进入dir来运行go构建,它的工作方式应该像它应该的那样,但是当我在go构建之后运行以下命令时:

./s3-graphite ./s3-石墨

I get the following error: 我收到以下错误:

INFO[0000] Starting s3-graphite...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x4e3256]

goroutine 1 [running]:
github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
    /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x76
main.NewS3(0x7ffc202bef6e, 0x1b, 0x7ffc202be684, 0x9, 0x1, 0x0, 0x0)
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x66
main.main()
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/main.go:19 +0x21c

goroutine 2 [runnable]:
runtime.forcegchelper()
    /usr/lib/golang/src/runtime/proc.go:90
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
    /usr/lib/golang/src/runtime/mgc0.go:82
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

goroutine 4 [runnable]:
runtime.runfinq()
    /usr/lib/golang/src/runtime/malloc.go:712
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

Here is my GOPATH: 这是我的GOPATH:

$GOPATH
-bash: /home/ec2-user/work/: Is a directory

Here is my dir where I execute the s3-graphite: 这是我执行s3-graphite的目录:

/home/ec2-user/work/src/github.com/adammck/s3-graphite

EDIT (updated with items from your answer: 编辑(使用答案中的项目进行了更新:

[ec2-user@s3-graphite]$ go version
go version go1.6.3 linux/amd64
[ec2-user@ s3-graphite]$ $GOPATH
-bash: /home/ec2-user/work: Is a directory
[ec2-user@ s3-graphite]$ pwd
/home/ec2-user/work/src/github.com/adammck/s3-graphite
[ec2-user@ s3-graphite]$ ./s3-graphite
INFO[0000] Starting s3-graphite...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x512aa2]

goroutine 1 [running]:
panic(0x873120, 0xc82000a0e0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
    /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x72
main.NewS3(0xc82001603a, 0x1b, 0xc82000e06a, 0x9, 0x1, 0x0, 0x0)
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x4a
main.main()
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/main.go:19 +0x229
[ec2-user@ s3-graphite]$

There seem to be a few things going on here. 这里似乎发生了一些事情。 One thing to check is that you are actually sourcing your .bashrc file after you set the environment variables in there. 要检查的一件事是,在其中设置环境变量之后,实际上是在采购.bashrc文件。 You should be able to run the env command and see your AWS keys, S3 configuration, and graphite settings in your current shell. 您应该能够运行env命令,并在当前外壳中查看AWS密钥,S3配置和石墨设置。

The second problem I see is that the library you are using hasn't been updated since last year. 我看到的第二个问题是您使用的库自去年以来就没有更新过。 As far as I know the AWS SDK for Go has changed a lot in the past year. 据我所知,AWS SDK for Go在过去一年中发生了很大变化。 The "panic:" line in your application's output gives a hint at the problem. 应用程序输出中的“ panic:”行提示了该问题。

panic: runtime error: invalid memory address or nil pointer dereference 紧急:运行时错误:无效的内存地址或nil指针取消引用

It seems like nil is being passed somewhere it is not supposed to be. 似乎nil正在传递到原本不应传递的地方。 Further down the panic output you can see the stacktrace for goroutine 1 says: 在紧急输出的更下方,您可以看到goroutine 1的stacktrace表示:

github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
    /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x76
main.NewS3(0x7ffc202bef6e, 0x1b, 0x7ffc202be684, 0x9, 0x1, 0x0, 0x0)
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x66

From this you can see that the NewS3 method is being called on line 20 of the s3.go file in the s3-graphite library. 由此可见,在s3-graphite库中s3.go文件的第20行上正在调用NewS3方法。 Then it goes to the aws-sdk-go library and tries to create a new S3 client. 然后,它进入aws-sdk-go库,并尝试创建一个新的S3客户端。 With the following arguments: 具有以下参数:

s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f) s3.New(0x0、0x0、0x0、0x0、0x0、0x3f)

My best guy is that your configuration is not exported to the environment you are running the executable in, or the s3-graphite library needs to be updated to work with the latest aws-sdk-go version. 我最好的人是您的配置没有导出到您在其中运行可执行文件的环境中,或者需要更新s3-graphite库以使用最新的aws-sdk-go版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM