douduan5753 2018-02-20 02:12
浏览 41

创建预签名网址时出现紧急错误

I'm trying to create a presigned url using the aws-sdk-go, but it it's failing with the following output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x138d40a]

goroutine 1 [running]:
github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/me/go/src/github.com/aws/aws-sdk-go/service/s3/service.go:47 +0x3a
main.main()
    /Users/me/go/src/Test/main.go:22 +0xa0
exit status 2

I'm not seeing where I'm making a mistake, perhaps someone more experience in go could point out to me:

package main

import (
    "fmt"
    "log"
    "time"

    // "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/s3"
    "github.com/kelseyhightower/envconfig"
)


func main() {
  var configuration s3.PutObjectInput
  err := envconfig.Process("configuration", &configuration)

  if err != nil {
    log.Fatal(err.Error())
  }

  svc := s3.New(nil)
  req, _ := svc.PutObjectRequest(&configuration)
  url, err := req.Presign(15 * time.Minute)
  fmt.Println("The url is ", url)
}
  • 写回答

1条回答 默认 最新

  • dongpin3794 2018-02-20 03:01
    关注

    You are passing a nil session while initialising s3 service svc := s3.New(nil), that why you get the nil pointer error.

    You can pass the session using following code,

    new import "github.com/aws/aws-sdk-go/aws/session"

    awsSession = session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))
    // Create S3 service client
    serviceS3 = s3.New(awsSession)
    

    You might need to change the session configurations based on how you plan to use the credentials. You can read more about credential configurations here https://docs.aws.amazon.com/sdk-for-go/api/

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大