-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudwatch.go
50 lines (41 loc) · 1.25 KB
/
cloudwatch.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
package cloudwatch
import (
"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/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
log "github.com/sirupsen/logrus"
)
// Cloudwatch is a wrapper around the aws cloudwatch service with some default config info
type Cloudwatch struct {
session *session.Session
Service cloudwatchiface.CloudWatchAPI
}
type CloudwatchOption func(*Cloudwatch)
func New(opts ...CloudwatchOption) *Cloudwatch {
client := Cloudwatch{}
for _, opt := range opts {
opt(&client)
}
if client.session != nil {
client.Service = cloudwatch.New(client.session)
}
return &client
}
func WithSession(sess *session.Session) CloudwatchOption {
return func(client *Cloudwatch) {
log.Debug("using aws session")
client.session = sess
}
}
func WithCredentials(key, secret, token, region string) CloudwatchOption {
return func(client *Cloudwatch) {
log.Debugf("creating new session with key id %s in region %s", key, region)
sess := session.Must(session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials(key, secret, token),
Region: aws.String(region),
}))
client.session = sess
}
}