Reintroduce AWS credential check to cloudwatch output (#3587)

This commit is contained in:
Adam Johnson 2018-01-03 00:33:16 +00:00 committed by Daniel Nelson
parent a440ed8d8c
commit 56be3d3236
1 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
internalaws "github.com/influxdata/telegraf/internal/config/aws" internalaws "github.com/influxdata/telegraf/internal/config/aws"
@ -70,7 +71,20 @@ func (c *CloudWatch) Connect() error {
Token: c.Token, Token: c.Token,
} }
configProvider := credentialConfig.Credentials() configProvider := credentialConfig.Credentials()
stsService := sts.New(configProvider)
params := &sts.GetCallerIdentityInput{}
_, err := stsService.GetCallerIdentity(params)
if err != nil {
log.Printf("E! cloudwatch: Cannot use credentials to connect to AWS : %+v \n", err.Error())
return err
}
c.svc = cloudwatch.New(configProvider) c.svc = cloudwatch.New(configProvider)
return nil return nil
} }