Skip to content

Commit 61079cc

Browse files
committed
fix(scf): apigw trigger function qualifier
1 parent cc0ae77 commit 61079cc

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/modules/scf/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class Scf {
231231
this.region,
232232
funcInfo,
233233
event[eventType],
234+
inputs.needSetTraffic,
234235
);
235236
try {
236237
const apigwOutput = await this.apigwClient.deploy(triggerInputs);
@@ -442,13 +443,6 @@ class Scf {
442443
}
443444

444445
const outputs = funcInfo;
445-
if (inputs.tags || inputs.events) {
446-
if (!funcInfo) {
447-
funcInfo = await this.getFunction(namespace, inputs.name);
448-
}
449-
await Promise.all([this.deployTags(funcInfo, inputs), this.deployTrigger(funcInfo, inputs)]);
450-
}
451-
452446
if (inputs.publish) {
453447
const { FunctionVersion } = await this.publishVersion({
454448
functionName: funcInfo.FunctionName,
@@ -459,7 +453,8 @@ class Scf {
459453
inputs.lastVersion = FunctionVersion;
460454
outputs.LastVersion = FunctionVersion;
461455
}
462-
if (inputs.traffic !== undefined && inputs.lastVersion) {
456+
inputs.needSetTraffic = inputs.traffic !== undefined && inputs.lastVersion;
457+
if (inputs.needSetTraffic) {
463458
await this.updateAliasTraffic({
464459
functionName: funcInfo.FunctionName,
465460
region: this.region,
@@ -471,6 +466,13 @@ class Scf {
471466
outputs.Traffic = inputs.traffic;
472467
}
473468

469+
if (inputs.tags || inputs.events) {
470+
if (!funcInfo) {
471+
funcInfo = await this.getFunction(namespace, inputs.name);
472+
}
473+
await Promise.all([this.deployTags(funcInfo, inputs), this.deployTrigger(funcInfo, inputs)]);
474+
}
475+
474476
console.log(`Deployed funtion ${funcInfo.FunctionName}.`);
475477
return outputs;
476478
}

src/modules/scf/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CONFIGS = require('./config');
66
* @param {object} funcInfo function information
77
* @param {object} inputs yml configuration
88
*/
9-
const formatApigwTrigger = (region, funcInfo, inputs) => {
9+
const formatApigwTrigger = (region, funcInfo, inputs, traffic = false) => {
1010
const { parameters, name } = inputs;
1111
const triggerInputs = {};
1212
triggerInputs.region = region;
@@ -18,6 +18,7 @@ const formatApigwTrigger = (region, funcInfo, inputs) => {
1818
ep.function = ep.function || {};
1919
ep.function.functionName = funcInfo.FunctionName;
2020
ep.function.functionNamespace = funcInfo.Namespace;
21+
ep.function.functionQualifier = traffic ? '$DEFAULT' : '$LATEST';
2122
return ep;
2223
});
2324
return {
@@ -159,10 +160,10 @@ const formatCmqTrigger = (region, funcInfo, inputs) => {
159160
};
160161
};
161162

162-
const formatTrigger = (type, region, funcInfo, inputs) => {
163+
const formatTrigger = (type, region, funcInfo, inputs, traffic) => {
163164
switch (type) {
164165
case 'apigw':
165-
return formatApigwTrigger(region, funcInfo, inputs);
166+
return formatApigwTrigger(region, funcInfo, inputs, traffic);
166167
case 'timer':
167168
return formatTimerTrigger(region, funcInfo, inputs);
168169
case 'cos':

0 commit comments

Comments
 (0)