Skip to content

Commit

Permalink
Merge pull request #46 from bbc/aws-assume-role
Browse files Browse the repository at this point in the history
Adds support for AWS Temporary Credentials
  • Loading branch information
Tim-B committed Nov 3, 2015
2 parents a6ae5e6 + d29f817 commit a5f5c9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ Default value: `null`
If you wish to use a specific AWS credentials profile you can specify it here, otherwise it will use the environment default.
You can also specify it with the environment variable `AWS_PROFILE`

##### options.roleArn
Type: `String`
Default value: `null`

If you wish to assume a specific role from an EC2 instance you can specify it here, otherwise it will use the environment default.

##### options.accessKeyId
Type: `String`
Default value: `null`
Expand Down Expand Up @@ -517,5 +523,3 @@ Adding more warnings for various failure cases

### 0.10.0
* Making NPM a regular dependency to resolve [#20](https://github.com/Tim-B/grunt-aws-lambda/issues/20) - [pull request by timdp](https://github.com/Tim-B/grunt-aws-lambda/pull/27)


10 changes: 10 additions & 0 deletions tasks/lambda_deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function (grunt) {

var options = this.options({
profile: null,
roleArn: null,
accessKeyId: null,
secretAccessKey: null,
credentialsJSON: null,
Expand All @@ -37,6 +38,15 @@ module.exports = function (grunt) {
AWS.config.credentials = credentials;
}

if (options.roleArn !== null) {
AWS.config.credentials = new AWS.EC2MetadataCredentials({
httpOptions: { timeout: 5000 } // 5 second timeout
});
AWS.config.credentials = new AWS.TemporaryCredentials({
RoleArn: options.roleArn
});
}

if (options.accessKeyId !== null && options.secretAccessKey !== null) {
AWS.config.update({accessKeyId: options.accessKeyId, secretAccessKey: options.secretAccessKey});
}
Expand Down

0 comments on commit a5f5c9a

Please sign in to comment.