/
index.js
47 lines (36 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const path = require('path');
const AWS = require('aws-sdk');
const Promise = require('bluebird');
const utils = require('./lib/utils');
module.exports = function (name, alias, opts) {
if (!name || typeof name !== 'string') {
return Promise.reject(new Error('Provide a AWS Lambda function name.'));
}
if (!alias || typeof alias !== 'string') {
return Promise.reject(new Error('Provide an alias name.'));
}
opts = opts || {};
// Load the credentials
AWS.config.region = opts.awsRegion || 'us-west-1';
if (opts.awsProfile) {
// Set the `credentials` property if a profile is provided
const objectCredentials = {
profile: opts.awsProfile
};
if (opts.awsFilename) {
objectCredentials.filename = path.resolve(process.cwd(), opts.awsFilename);
}
AWS.config.credentials = new AWS.SharedIniFileCredentials(objectCredentials);
}
// Create a lambda object
const lambda = new AWS.Lambda();
const options = {
FunctionName: name,
Name: alias
};
if (opts.version) {
options.FunctionVersion = opts.version;
}
return utils.updateOrCreate(lambda, options);
};