Skip to content

Commit

Permalink
Closes #1085 - allow for specifying AWS credentials in config.
Browse files Browse the repository at this point in the history
closes #1085
closes #1086
  • Loading branch information
johnrengelman authored and sparrc committed Apr 26, 2016
1 parent 44c945b commit 1c4043a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ based on _prefix_ in addition to globs. This means that a filter like
- [#1041](https:/influxdata/telegraf/issues/1041): Add `n_cpus` field to the system plugin.
- [#1072](https:/influxdata/telegraf/pull/1072): New Input Plugin: filestat.
- [#1066](https:/influxdata/telegraf/pull/1066): Replication lag metrics for MongoDB input plugin
- [#1086](https:/influxdata/telegraf/pull/1086): Ability to specify AWS keys in config file. Thanks @johnrengleman!

### Bugfixes

Expand Down
15 changes: 15 additions & 0 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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"
Expand All @@ -18,6 +19,8 @@ import (
type (
CloudWatch struct {
Region string `toml:"region"`
AccessKey string `toml:"access_key"`
SecretKey string `toml:"secret_key"`
Period internal.Duration `toml:"period"`
Delay internal.Duration `toml:"delay"`
Namespace string `toml:"namespace"`
Expand Down Expand Up @@ -53,6 +56,15 @@ func (c *CloudWatch) SampleConfig() string {
## 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 = ""
## Requested CloudWatch aggregation Period (required - must be a multiple of 60s)
period = '1m'
Expand Down Expand Up @@ -152,6 +164,9 @@ func (c *CloudWatch) initializeCloudWatch() error {
config := &aws.Config{
Region: aws.String(c.Region),
}
if c.AccessKey != "" || c.SecretKey != "" {
config.Credentials = credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, "")
}

c.client = cloudwatch.New(session.New(config))
return nil
Expand Down
19 changes: 17 additions & 2 deletions plugins/outputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -16,15 +17,26 @@ 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
}

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'
`
Expand All @@ -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))

Expand Down
16 changes: 16 additions & 0 deletions plugins/outputs/kinesis/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/kinesis"

Expand All @@ -17,6 +18,8 @@ import (

type KinesisOutput struct {
Region string `toml:"region"`
AccessKey string `toml:"access_key"`
SecretKey string `toml:"secret_key"`
StreamName string `toml:"streamname"`
PartitionKey string `toml:"partitionkey"`
Format string `toml:"format"`
Expand All @@ -27,6 +30,16 @@ type KinesisOutput struct {
var sampleConfig = `
## Amazon REGION of kinesis endpoint.
region = "ap-southeast-2"
## 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 = ""
## Kinesis StreamName must exist prior to starting telegraf.
streamname = "StreamName"
## PartitionKey as used for sharding data.
Expand Down Expand Up @@ -65,6 +78,9 @@ func (k *KinesisOutput) Connect() error {
Config := &aws.Config{
Region: aws.String(k.Region),
}
if k.AccessKey != "" || k.SecretKey != "" {
Config.Credentials = credentials.NewStaticCredentials(k.AccessKey, k.SecretKey, "")
}
svc := kinesis.New(session.New(Config))

KinesisParams := &kinesis.ListStreamsInput{
Expand Down

0 comments on commit 1c4043a

Please sign in to comment.