Closes #1085 - allow for specifying AWS credentials in config.
closes #1085 closes #1086
This commit is contained in:
committed by
Cameron Sparr
parent
44c945b9f5
commit
1c4043ab39
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user