不能在dynamodb.New的参数中使用cfg(类型“... aws / aws-sdk-go-v2 / aws”.Config“)作为类型(类型...)

时间:2018-02-28 13:32:07

标签: go amazon-s3 amazon-dynamodb

我正在尝试创建一个Go程序,该程序使用SDK V2创建Put预签名URL并保存到DynamoDB中。我只能弄清楚如何创建预先签名的URL,而不是如何保存到DynamoDB中,因为发生了以下错误:

./main.go:67:24: cannot use cfg (type "Test2/vendor/github.com/aws/aws-sdk-go-v2/aws".Config) as type "github.com/aws/aws-sdk-go-v2/aws".Config in argument to dynamodb.New

这是代码:

package main

import (
  "time"
  // "fmt"

  "github.com/aws/aws-sdk-go-v2/aws"
  "github.com/aws/aws-sdk-go-v2/aws/endpoints"
  "github.com/aws/aws-sdk-go-v2/aws/external"
  "github.com/aws/aws-sdk-go-v2/service/dynamodb"
  "github.com/aws/aws-sdk-go-v2/service/s3"
  "github.com/kelseyhightower/envconfig"

)


type Bucket struct {
  Name string
}

// Using the SDK's default configuration, loading additional config
// and credentials values from the environment variables, shared
// credentials, and shared configuration files
var cfg, err = external.LoadDefaultAWSConfig()

// Description
var bucket Bucket

func main() {
    err = envconfig.Process("bucket", &bucket)
    if err != nil {
        panic(err.Error())
    } else if len(cfg.Region) > 0 {
        // Set Region to us-east-1 as default.
        cfg.Region = endpoints.UsEast1RegionID
    }

    url, err := createPresignedPutURL()
    if err != nil {
        panic(err.Error())
    }

    _, err = createNewExtraction(url)
    if err != nil {
        panic(err.Error())
    }
}

func createPresignedPutURL() (string, error) {
    svc := s3.New(cfg)
    req := svc.PutObjectRequest(&s3.PutObjectInput{
        Bucket: aws.String("garimpo-extractions"),
        Key: aws.String("uuid"),
    })

    url, _, err := req.PresignRequest(15 * time.Minute)
    if err != nil {
        panic(err)
    }
    return url, nil
}

func createNewExtraction(url string) (string, error) {
    svc := dynamodb.New(cfg) // ERROR IS HERE
    return "", nil
    // req := svc.ScanRequest(&dynamodb.ScanInput{
    //     TableName: aws.String("extractions-development"),
    // })

    // // // Fire request with req.Send().
    // res, err := req.Send(); if err != nil {
    //     return "", err
    // }
    // return res, nil
}

我真的不明白发生了什么。我正在使用cfg创建与s3的连接,并且正在工作,但是当我尝试使用DynamoDB创建连接时,它会失败。

0 个答案:

没有答案