8000 Add AWS SDK Profile Credentials by beeva-arturomartinez · Pull Request #1 · kecaps/node-lambda · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/node-lambda
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var CONFIG_FILE = process.env.CONFIG_FILE || '';
var AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
var AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
var AWS_SESSION_TOKEN = process.env.AWS_SESSION_TOKEN || '';
var AWS_PROFILE = process.env.AWS_PROFILE || '';
var AWS_REGION = process.env.AWS_REGION || 'us-east-1,us-west-2,eu-west-1';
var AWS_FUNCTION_NAME = process.env.AWS_FUNCTION_NAME || packageJson.name;
var AWS_HANDLER = process.env.AWS_HANDLER || 'index.handler';
Expand All @@ -34,6 +35,7 @@ program
.option('-a, --accessKey [' + AWS_ACCESS_KEY_ID + ']', 'AWS Access Key', AWS_ACCESS_KEY_ID)
.option('-s, --secretKey [' + AWS_SECRET_ACCESS_KEY + ']', 'AWS Secret Key', AWS_SECRET_ACCESS_KEY)
.option('-k, --sessionToken [' + AWS_SESSION_TOKEN + ']', 'AWS Session Token', AWS_SESSION_TOKEN)
.option('--profile ['+AWS_PROFILE+']','AWS Profile',AWS_PROFILE)
.option('-r, --region [' + AWS_REGION + ']', 'AWS Region', AWS_REGION)
.option('-n, --functionName [' + AWS_FUNCTION_NAME + ']', 'Lambda FunctionName', AWS_FUNCTION_NAME)
.option('-h, --handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
Expand All @@ -57,6 +59,7 @@ program
.description('Create zipped package for Amazon Lambda deployment')
.option('-p, --packageDirectory [' + PACKAGE_DIRECTORY + ']', 'Local Package Directory', PACKAGE_DIRECTORY)
.option('-n, --functionName [' + AWS_FUNCTION_NAME + ']', 'Lambda FunctionName', AWS_FUNCTION_NAME)
.option('-h, --handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
.option('-e, --environment [' + AWS_ENVIRONMENT + ']', 'Choose environment {dev, staging, production}',
AWS_ENVIRONMENT)
.option('-f, --configFile [' + CONFIG_FILE + ']',
Expand Down
1 change: 1 addition & 0 deletions lib/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AWS_ENVIRONMENT=development
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_SESSION_TOKEN=
AWS_PROFILE=
AWS_ROLE_ARN=your_amazon_role
AWS_REGION=us-east-1
AWS_FUNCTION_NAME=
Expand Down
26 changes: 17 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,25 @@ Lambda.prototype.deploy = function (program) {
console.log('=> Uploading zip file to AWS Lambda ' + region + ' with parameters:');
console.log(params);

var aws_security = {
accessKeyId: program.accessKey,
secretAccessKey: program.secretKey,
region: region
};
if (program.profile){
var credentials = new aws.SharedIniFileCredentials({profile: program.profile});
aws.config.credentials = credentials;
aws.config.update({region: region});
} else {
var aws_security = {
accessKeyId: program.accessKey,
secretAccessKey: program.secretKey,
region: region
};

if (program.sessionToken){
aws_security.sessionToken = program.sessionToken;
};

aws.config.update(aws_security);
}

if (program.sessionToken){
aws_security.sessionToken = program.sessionToken;
};

aws.config.update(aws_security);

var lambda = new aws.Lambda({
apiVersion: '2014-11-11'
Expand Down
0