I'm trying to create a Go program that creates a Put Pre-signed URL and saves into DynamoDB, using the SDK V2. I was able to figure it out only how to create the pre-signed url, but not how to save into DynamoDB, because the following error is happening:
./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
And this is the code:
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
}
I'm not really understanding what is going on. I'm using the cfg
to create a connection to s3, and is working, but when I try to create a connection with DynamoDB, it fails.