2016-07-25 86 views
0

我目前正在尝试运行以下Golang建设首次在亚马逊的Linux发行版:GO脚本运行错误亚马逊AWS S3

README这里:

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

在此之后,我把我的变量在我的.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 

设置我GOPATH以下几点:

export GOPATH="$HOME/work/" 

我用cd命令进入目录运行去构建它的工作原理像它应该,但是当我去跑旅途生成后如下:

。/S3石墨

我得到以下错误:

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 

这里是我的GOPATH:

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

这里是我的目录,我执行S3-石墨:

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

EDIT(与你的答案项更新:

[[email protected]]$ go version 
go version go1.6.3 linux/amd64 
[[email protected] s3-graphite]$ $GOPATH 
-bash: /home/ec2-user/work: Is a directory 
[[email protected] s3-graphite]$ pwd 
/home/ec2-user/work/src/github.com/adammck/s3-graphite 
[[email protected] 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 
[[email protected] s3-graphite]$ 

回答

0

似乎有是几件事情怎么回事。需要检查的一件事是,在您设置环境变量后,您实际上正在采购您的.bashrc文件。您应该能够运行env命令并在当前shell中查看您的AWS密钥,S3配置和石墨设置。

我看到的第二个问题是您使用的库自去年以来没有更新过。据我所知,去年的AWS SDK for Go发生了很大变化。应用程序输出中的“恐慌:”行提示了该问题。

panic: runtime error: invalid memory address or nil pointer dereference

好像nil被传递的地方它不应该是。再往下恐慌输出,你可以看到的goroutine 1堆栈跟踪说:

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 

从这里就可以看出,NewS3方法被调用上的S3-石墨库s3.go文件的第20行。然后它转到aws-sdk-go库并尝试创建一个新的S3客户端。使用以下参数:

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

我最好的家伙,你的配置不导出到环境中,你正在运行的可执行文件,或S3石墨库需要更新了最新的工作AWS-SDK -go版本。

+0

感谢您的回复。我更新了GO版本,并确保获得$ GOPATH以及用我需要的数据获取.bashrc文件,但这仍然是不成功的。请参阅主文章上方的编辑。 @ rking788 – hijaked79