Closes #1085 - allow for specifying AWS credentials in config.

closes #1085
closes #1086
This commit is contained in:
John Engelman
2016-04-23 13:19:04 -05:00
committed by Cameron Sparr
parent 44c945b9f5
commit 1c4043ab39
4 changed files with 49 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"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"
@@ -16,8 +17,10 @@ import (
)
type CloudWatch struct {
Region string // AWS Region
Namespace string // CloudWatch Metrics Namespace
Region string `toml:"region"` // AWS Region
AccessKey string `toml:"access_key"` // Explicit AWS Access Key ID
SecretKey string `toml:"secret_key"` // Explicit AWS Secret Access Key
Namespace string `toml:"namespace"` // CloudWatch Metrics Namespace
svc *cloudwatch.CloudWatch
}
@@ -25,6 +28,15 @@ var sampleConfig = `
## Amazon REGION
region = 'us-east-1'
## Amazon Credentials
## Credentials are loaded in the following order
## 1) explicit credentials from 'access_key' and 'secret_key'
## 2) environment variables
## 3) shared credentials file
## 4) EC2 Instance Profile
#access_key = ""
#secret_key = ""
## Namespace for the CloudWatch MetricDatums
namespace = 'InfluxData/Telegraf'
`
@@ -41,6 +53,9 @@ func (c *CloudWatch) Connect() error {
Config := &aws.Config{
Region: aws.String(c.Region),
}
if c.AccessKey != "" || c.SecretKey != "" {
Config.Credentials = credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, "")
}
svc := cloudwatch.New(session.New(Config))