package aws import ( "errors" "git.trj.tw/golang/go-ddns-svc/module/config" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53" ) // AWSClient - type AWSClient struct { Session *session.Session Config *aws.Config Services struct { R53 *route53.Route53 } } var client *AWSClient // NewAWS - func NewAWS() error { conf := config.GetConfig() awsConf := &aws.Config{} awsConf.Region = aws.String("us-east-1") var sess *session.Session if conf.AWS.SharedConfig { if len(conf.AWS.SharedName) == 0 { return errors.New("aws shared config name empty") } awsConf.Credentials = credentials.NewSharedCredentials("", conf.AWS.SharedName) } else { awsConf.Credentials = credentials.NewStaticCredentials(conf.AWS.AccessKey, conf.AWS.SecretKey, "") } sess = session.New(awsConf) client = &AWSClient{} client.Session = sess client.Config = awsConf return nil }