aws sqs: Use implicit creds and region by default, explicit if specified (#340)
* Use implicit creds by default, explicit if specified * Remove log lines * Support implicit region as well * gofmt-ed file * removed a newline * Use a separate package for aws auth stuff * Rename + alias imports * gofmt * goimportsed file Co-authored-by: Yaron Schneider <yaronsc@microsoft.com>
This commit is contained in:
parent
b54585c4f0
commit
52e37224e5
|
@ -0,0 +1,24 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetClient(accessKey string, secretKey string, region string) (*session.Session, error) {
|
||||||
|
awsConfig := aws.NewConfig()
|
||||||
|
|
||||||
|
if region != "" {
|
||||||
|
awsConfig = awsConfig.WithRegion(region)
|
||||||
|
}
|
||||||
|
if accessKey != "" && secretKey != "" {
|
||||||
|
awsConfig = awsConfig.WithCredentials(credentials.NewStaticCredentials(accessKey, secretKey, ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
awsSession, err := session.NewSession(awsConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return awsSession, nil
|
||||||
|
}
|
|
@ -9,13 +9,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
||||||
"github.com/dapr/dapr/pkg/logger"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
|
||||||
"github.com/aws/aws-sdk-go/service/sqs"
|
"github.com/aws/aws-sdk-go/service/sqs"
|
||||||
|
aws_auth "github.com/dapr/components-contrib/authentication/aws"
|
||||||
"github.com/dapr/components-contrib/bindings"
|
"github.com/dapr/components-contrib/bindings"
|
||||||
|
"github.com/dapr/dapr/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AWSSQS allows receiving and sending data to/from AWS SQS
|
// AWSSQS allows receiving and sending data to/from AWS SQS
|
||||||
|
@ -126,14 +124,11 @@ func (a *AWSSQS) parseSQSMetadata(metadata bindings.Metadata) (*sqsMetadata, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AWSSQS) getClient(metadata *sqsMetadata) (*sqs.SQS, error) {
|
func (a *AWSSQS) getClient(metadata *sqsMetadata) (*sqs.SQS, error) {
|
||||||
sess, err := session.NewSession(&aws.Config{
|
sess, err := aws_auth.GetClient(metadata.AccessKey, metadata.SecretKey, metadata.Region)
|
||||||
Region: aws.String(metadata.Region),
|
|
||||||
Credentials: credentials.NewStaticCredentials(metadata.AccessKey, metadata.SecretKey, ""),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c := sqs.New(sess)
|
c := sqs.New(sess)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue