Created
May 22, 2024 14:57
-
-
Save jerry42/b3dbb2670cc665e1b20e2905cd1bed5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const shell = require("shelljs"); // npm install shelljs | |
const args = process.argv; | |
// updateVersion.js [version] [filter=optional] | |
let filter = ""; | |
if (args[2] == undefined) { | |
console.log(`You must enter a alias name`); | |
return false; | |
} | |
const version = args[2]; | |
if (args[3] != undefined) { | |
filter = args[3]; | |
} | |
let data = shell.exec("aws lambda list-functions | grep FunctionName", { silent: true }); | |
let ar = data.stdout.split("\n"); | |
let funcList = []; | |
for (let i = 0; i < ar.length - 1; i++) { | |
let t = ar[i].split(":"); | |
let func = t[1].replace('"', "").replace('"', "").replace(",", "").trim(); | |
if (filter.length > 0) { | |
if (func.indexOf(filter) != -1) { | |
funcList.push(func); | |
} | |
} else { | |
funcList.push(func); | |
} | |
} | |
for (let i = 0; i < funcList.length; i++) { | |
let cmdVersion = `aws lambda publish-version --function-name "${funcList[i]}" --description "${version}"`; | |
let retour = JSON.parse(shell.exec(cmdVersion)); | |
let publishedVersion = retour.Version; | |
let cmdAlias = `aws lambda create-alias --function-name "${funcList[i]}" --name "${version}" --function-version "${publishedVersion}"`; | |
shell.exec(cmdAlias); | |
let cmdPermission = `aws lambda add-permission --function-name "${funcList[i]}:${version}" --principal apigateway.amazonaws.com --action lambda:InvokeFunction --statement-id "auto-${version}"`; | |
shell.exec(cmdPermission); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment