forked from nzoschke/gofaas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws.go
78 lines (67 loc) · 2.04 KB
/
aws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gofaas
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/aws/aws-xray-sdk-go/xray"
)
// AWS Clients that can be mocked for testing
var (
DynamoDB = NewDynamoDB()
KMS = NewKMS()
Lambda = NewLambda()
S3 = NewS3()
SNS = NewSNS()
sess = session.Must(session.NewSession())
)
func init() {
xray.Configure(xray.Config{
LogLevel: "info",
})
}
// DynamoDBAPI is a subset of dynamodbiface.DynamoDBAPI
type DynamoDBAPI interface {
DeleteItemWithContext(ctx aws.Context, input *dynamodb.DeleteItemInput, opts ...request.Option) (*dynamodb.DeleteItemOutput, error)
GetItemWithContext(ctx aws.Context, input *dynamodb.GetItemInput, opts ...request.Option) (*dynamodb.GetItemOutput, error)
PutItemWithContext(ctx aws.Context, input *dynamodb.PutItemInput, opts ...request.Option) (*dynamodb.PutItemOutput, error)
}
// KMSAPI is a subset of kmsiface.KMSAPI
type KMSAPI interface {
DecryptWithContext(ctx aws.Context, input *kms.DecryptInput, opts ...request.Option) (*kms.DecryptOutput, error)
EncryptWithContext(ctx aws.Context, input *kms.EncryptInput, opts ...request.Option) (*kms.EncryptOutput, error)
}
// NewDynamoDB is an xray instrumented DynamoDB client
func NewDynamoDB() DynamoDBAPI {
c := dynamodb.New(sess)
xray.AWS(c.Client)
return c
}
// NewKMS is an xray instrumented KMS client
func NewKMS() KMSAPI {
c := kms.New(sess)
xray.AWS(c.Client)
return c
}
// NewLambda is an xray instrumented Lambda client
func NewLambda() *lambda.Lambda {
c := lambda.New(sess)
xray.AWS(c.Client)
return c
}
// NewS3 is an xray instrumented S3 client
func NewS3() *s3.S3 {
c := s3.New(sess)
xray.AWS(c.Client)
return c
}
// NewSNS is an xray instrumented SNS client
func NewSNS() *sns.SNS {
c := sns.New(sess)
xray.AWS(c.Client)
return c
}