doyhq66282 2016-07-25 17:35
浏览 93

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

I'm currently attempting to run the following Golang build for the first time on a Amazon Linux Distro:

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:

# 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:

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:

./s3-graphite

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
-bash: /home/ec2-user/work/: Is a directory

Here is my dir where I execute the 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]$
  • 写回答

1条回答 默认 最新

  • douzi8127 2016-07-25 20:02
    关注

    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. You should be able to run the env command and see your AWS keys, S3 configuration, and graphite settings in your current shell.

    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. The "panic:" line in your application's output gives a hint at the problem.

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

    It seems like nil is being passed somewhere it is not supposed to be. Further down the panic output you can see the stacktrace for goroutine 1 says:

    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. Then it goes to the aws-sdk-go library and tries to create a new S3 client. With the following arguments:

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)