更新环境变量与触发器
This commit is contained in:
1
.github/workflows/deploy_tencent_scf.yml
vendored
1
.github/workflows/deploy_tencent_scf.yml
vendored
@@ -22,6 +22,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm install tencentcloud-sdk-nodejs
|
npm install tencentcloud-sdk-nodejs
|
||||||
|
npm install js-yaml
|
||||||
|
|
||||||
- name: "将Secrets里面配置的变量添加到severless.yml里面作为环境变量"
|
- name: "将Secrets里面配置的变量添加到severless.yml里面作为环境变量"
|
||||||
run: |
|
run: |
|
||||||
|
@@ -20,7 +20,7 @@ const clientConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const client = new ScfClient(clientConfig);
|
const client = new ScfClient(clientConfig);
|
||||||
const params = {
|
let params = {
|
||||||
"Handler": "index.main_handler",
|
"Handler": "index.main_handler",
|
||||||
"FunctionName": process.env.TENCENT_FUNCTION_NAME, // 云函数程序名,例如 jd_scripts
|
"FunctionName": process.env.TENCENT_FUNCTION_NAME, // 云函数程序名,例如 jd_scripts
|
||||||
"ZipFile": contents_in_base64
|
"ZipFile": contents_in_base64
|
||||||
@@ -33,3 +33,47 @@ client.UpdateFunctionCode(params).then(
|
|||||||
console.error("error", err);
|
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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user