We start with an existing go module and an existing main.go.
The import for the config is:
import "github.com/aws/aws-sdk-go-v2/config"
After adding this line to the import section, you have to download the library with:
go get "github.com/aws/aws-sdk-go-v2/config"
I tend to init the configuration and the client in the init function:
func init(){
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
panic("configuration error, " + err.Error())
}
}
This code alone will not work, because
So the import becomes:
import (
"context"
"github.com/aws/aws-sdk-go-v2/config"
)
func init(){
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
panic("configuration error, " + err.Error())
}
}
In the next step we create the client.
See the full source on github.