更新环境变量与触发器

This commit is contained in:
shylocks
2021-01-25 22:02:44 +08:00
parent 88f960595f
commit 6c2ede86b4
2 changed files with 46 additions and 1 deletions

View File

@ -22,6 +22,7 @@ jobs:
run: |
npm install
npm install tencentcloud-sdk-nodejs
npm install js-yaml
- name: "将Secrets里面配置的变量添加到severless.yml里面作为环境变量"
run: |

View File

@ -20,7 +20,7 @@ const clientConfig = {
};
const client = new ScfClient(clientConfig);
const params = {
let params = {
"Handler": "index.main_handler",
"FunctionName": process.env.TENCENT_FUNCTION_NAME, // 云函数程序名,例如 jd_scripts
"ZipFile": contents_in_base64
@ -33,3 +33,47 @@ client.UpdateFunctionCode(params).then(
console.error("error", err);
}
);
// 更新环境变量
let vars = []
for(let key in process.env){
vars.push({
"Key": key,
"Value": process.env[key]
})
}
params = {
"Environment": {
"Variables": vars
}
};
client.UpdateFunctionConfiguration(params).then(
(data) => {
console.log(data);
},
(err) => {
console.error("error", err);
}
);
// 更新触发器
const inputYML = 'serverless.yml';
const yaml = require('js-yaml');
const obj = yaml.load(fs.readFileSync(inputYML, {encoding: 'utf-8'}))
for(let vo of obj.inputs.events){
let param = {
'Type' : "timer",
'TriggerDesc' : vo.timer.parameters.cronExpression,
'CustomArgument' : vo.timer.parameters.argument,
'Enable' : "true"
}
client.CreateTrigger(param).then(
(data) => {
console.log(data);
},
(err) => {
console.error("error", err);
}
);
}