-
Notifications
You must be signed in to change notification settings - Fork 1
/
createAlias.js
30 lines (27 loc) · 1.15 KB
/
createAlias.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
"use strict";
const AWS = require('aws-sdk');
const updateAPIGWPolicy = require('./updateAPIGWPolicy');
/**
* Create Lambda Alias
* @module
*/
/**
* Create a new alias for the last version published for lambda and assigns
* permissions to the appropriate API GW resource for that alias
*
* @param {string} functionName name of lambda function and current branch
* @param {string} name the name/alias to be given to the new lambda version
* @param {string} version the most recent version which was just published
* @param {object} apiInfo Api info found in package json. Used with updateAPIGWPolicy
* @return {Promise} Update Api GW Policy response
*/
module.exports = function(functionName, name, version, api_info, account, aws_config) {
const lambda = new AWS.Lambda(aws_config);
if (!version) return Promise.reject('Invalid version');
else return lambda.createAlias({
FunctionName: functionName,
FunctionVersion: version.toString(),
Name: name
}).promise()
.then(() => (api_info && api_info.apiId) ? updateAPIGWPolicy(functionName, name, api_info, account, aws_config) : Promise.resolve());
};