Skip to content

Commit a6ae5e6

Browse files
committed
Merge pull request #34 from robbiet480/master
Allow for all credential forms
2 parents 699e067 + 8340f87 commit a6ae5e6

File tree

2 files changed

+62
-40
lines changed

2 files changed

+62
-40
lines changed

README.md

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ npm packages which should be bundled with your lambda function must be included
6161
[Read More](#default-options-1)
6262

6363

64-
## Specify AWS credentials in ~/.aws/credentials
64+
## Authenticating to AWS
6565

66-
This will save you from accidentally committing AWS credentials.
67-
68-
[Read More](#aws-credentials)
66+
This library supports providing credentials for AWS via an IAM Role, an AWS CLI profile, environment variables, a JSON file on disk, or passed in credentials.
67+
To learn more, please see the [below section](#aws-credentials)
6968

7069
## grunt-aws-lambda tasks
7170

@@ -346,6 +345,25 @@ Type: `String`
346345
Default value: `null`
347346

348347
If you wish to use a specific AWS credentials profile you can specify it here, otherwise it will use the environment default.
348+
You can also specify it with the environment variable `AWS_PROFILE`
349+
350+
##### options.accessKeyId
351+
Type: `String`
352+
Default value: `null`
353+
354+
If you wish to use hardcoded AWS credentials you should specify the Access Key ID here
355+
356+
##### options.secretAccessKey
357+
Type: `String`
358+
Default value: `null`
359+
360+
If you wish to use hardcoded AWS credentials you should specify the Secret Access Key here
361+
362+
##### options.credentialsJSON
363+
Type: `String`
364+
Default value: `null`
365+
366+
If you wish to use hardcoded AWS credentials saved in a JSON file, put the path to the JSON here. The JSON must conform to the [AWS format](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk).
349367

350368
##### options.region
351369
Type: `String`
@@ -357,8 +375,8 @@ Specify the AWS region your functions will be uploaded to. Note that if an ARN i
357375
Type: `Integer`
358376
Default value: `null`
359377
Depending on your Lambda function, you might need to increase the timeout value. The default timeout assigned by AWS is currently 3 seconds.
360-
If you wish to increase this timeout set the value here.
361-
378+
If you wish to increase this timeout set the value here.
379+
362380
##### options.memory
363381
Type: `Integer`
364382
Default value: `null`
@@ -392,7 +410,7 @@ grunt.initConfig({
392410
arn: 'arn:aws:lambda:us-east-1:123456781234:function:my-function',
393411
options: {
394412
timeout : 10,
395-
memory: 256
413+
memory: 256
396414
}
397415
}
398416
}
@@ -414,55 +432,46 @@ You can then run `grunt deploy` to perform both these functions in one step.
414432

415433
### AWS credentials
416434

417-
The AWS SDK is configured to look for credentials in the environment, that is it will look in `~/.aws/credentials`.
435+
The AWS SDK is configured to look for credentials in the following order:
418436

419-
This file should look something like:
420-
```
421-
[default]
422-
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
423-
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
424-
```
437+
1. an IAM Role (if running on EC2)
438+
2. an AWS CLI profile (from `~/.aws/credentials`)
439+
3. environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`)
440+
4. a JSON file on disk
441+
5. Hardcoded credentials passed into grunt-aws
425442

426443
For more information [read this documentation](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html).
427444

428445
### AWS permissions
429446

430-
To run the deploy command the AWS credentials require permissions to access lambda including `lambda:UploadFunction` and
431-
`iam:PassRole` for the role which is assigned to the function.
447+
To run the deploy command the AWS credentials require permissions to access lambda including `lambda:GetFunction`,
448+
`lambda:UploadFunction`, `lambda:UpdateFunctionCode`, `lambda:UpdateFunctionConfiguration` and
449+
`iam:PassRole` for the role which is assigned to the function.
432450

433-
It is recommended that the following two policies be applied to the user:
451+
It is recommended that the following policy be applied to the user:
434452

435453
```json
436454
{
437455
"Version": "2012-10-17",
438456
"Statement": [
439457
{
440-
"Sid": "Stmt1404366560000",
441-
"Effect": "Allow",
458+
"Sid": "Stmt1442787227063",
442459
"Action": [
443-
"lambda:*"
460+
"lambda:GetFunction",
461+
"lambda:UploadFunction",
462+
"lambda:UpdateFunctionCode",
463+
"lambda:UpdateFunctionConfiguration"
444464
],
445-
"Resource": [
446-
"*"
447-
]
448-
}
449-
]
450-
}
451-
```
452-
453-
```json
454-
{
455-
"Version": "2012-10-17",
456-
"Statement": [
457-
{
458-
"Sid": "Stmt1404366560000",
459465
"Effect": "Allow",
466+
"Resource": "arn:aws:lambda:*"
467+
},
468+
{
469+
"Sid": "Stmt1442787265773",
460470
"Action": [
461471
"iam:PassRole"
462472
],
463-
"Resource": [
464-
"arn:aws:iam::<my_account_id>:role/<my_role_name>"
465-
]
473+
"Effect": "Allow",
474+
"Resource": "arn:aws:iam::<my_account_id>:role/<my_role_name>"
466475
}
467476
]
468477
}
@@ -483,15 +492,15 @@ Adding more warnings for various failure cases
483492

484493
### 0.4.0
485494

486-
* Added support for succeed and fail functions - [pull request by jonyo](https://github.com/Tim-B/grunt-aws-lambda/pull/11)
495+
* Added support for succeed and fail functions - [pull request by jonyo](https://github.com/Tim-B/grunt-aws-lambda/pull/11)
487496
* Added NPM to package.json - [pull request by jonyo](https://github.com/Tim-B/grunt-aws-lambda/pull/13), should address [issue 2](https://github.com/Tim-B/grunt-aws-lambda/issues/2#issuecomment-104805707)
488497
* Added timeout and memory options - [timeout pull request by aidancasey](https://github.com/Tim-B/grunt-aws-lambda/pull/3)
489498
* Bumped aws-sdk version
490499
* Bumped adm-zip version, will hopefully address [issue 4](https://github.com/Tim-B/grunt-aws-lambda/issues/4)
491500

492501
### 0.5.0
493-
* Fixed issue where dotfiles weren't packaged - [see issue 17](https://github.com/Tim-B/grunt-aws-lambda/issues/17)
494-
* Fixed issue where task could be done before zip writing is finished - [pull request by qen](https://github.com/Tim-B/grunt-aws-lambda/pull/16)
502+
* Fixed issue where dotfiles weren't packaged - [see issue 17](https://github.com/Tim-B/grunt-aws-lambda/issues/17)
503+
* Fixed issue where task could be done before zip writing is finished - [pull request by qen](https://github.com/Tim-B/grunt-aws-lambda/pull/16)
495504
* Monkey patched node-archiver to force permissions to be 777 for all files in package - [see issue 6](https://github.com/Tim-B/grunt-aws-lambda/issues/6)
496505

497506
### 0.6.0

tasks/lambda_deploy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ module.exports = function (grunt) {
2424

2525
var options = this.options({
2626
profile: null,
27+
accessKeyId: null,
28+
secretAccessKey: null,
29+
credentialsJSON: null,
2730
region: 'us-east-1',
2831
timeout: null,
2932
memory: null
@@ -34,6 +37,16 @@ module.exports = function (grunt) {
3437
AWS.config.credentials = credentials;
3538
}
3639

40+
if (options.accessKeyId !== null && options.secretAccessKey !== null) {
41+
AWS.config.update({accessKeyId: options.accessKeyId, secretAccessKey: options.secretAccessKey});
42+
}
43+
44+
if (options.credentialsJSON !== null) {
45+
AWS.config.loadFromPath(options.credentialsJSON);
46+
}
47+
48+
AWS.config.update({region: options.region});
49+
3750
var deploy_function = grunt.config.get('lambda_deploy.' + this.target + '.function');
3851
var deploy_arn = grunt.config.get('lambda_deploy.' + this.target + '.arn');
3952
var deploy_package = grunt.config.get('lambda_deploy.' + this.target + '.package');

0 commit comments

Comments
 (0)