@@ -312,6 +312,83 @@ class Scf {
312
312
}
313
313
}
314
314
315
+ /**
316
+ * publish function version
317
+ * @param {object } inputs publish version parameter
318
+ */
319
+ async publishVersion ( inputs ) {
320
+ const publishInputs = {
321
+ Action : 'PublishVersion' ,
322
+ Version : '2018-04-16' ,
323
+ Region : inputs . region ,
324
+ FunctionName : inputs . functionName ,
325
+ Description : inputs . description || 'Published by Serverless Component' ,
326
+ Namespace : inputs . namespace || 'default' ,
327
+ } ;
328
+ const res = await this . scfClient . request ( publishInputs ) ;
329
+ if ( res . Response && res . Response . Error ) {
330
+ throw new TypeError (
331
+ 'API_SCF_PublishVersion' ,
332
+ JSON . stringify ( res . Response ) ,
333
+ null ,
334
+ res . Response . RequestId ,
335
+ ) ;
336
+ }
337
+ return res . Response ;
338
+ }
339
+
340
+ async publishVersionAndConfigTraffic ( inputs ) {
341
+ const publishInputs = {
342
+ Action : 'CreateAlias' ,
343
+ Version : '2018-04-16' ,
344
+ Region : inputs . region ,
345
+ FunctionName : inputs . functionName ,
346
+ FunctionVersion : inputs . functionVersion ,
347
+ Name : inputs . aliasName ,
348
+ Namespace : inputs . namespace || 'default' ,
349
+ RoutingConfig : {
350
+ AdditionalVersionWeights : [ { Version : inputs . functionVersion , Weight : 1 - inputs . traffic } ] ,
351
+ } ,
352
+ Description : inputs . description || 'Published by Serverless Component' ,
353
+ } ;
354
+ const res = await this . scfClient . request ( publishInputs ) ;
355
+ if ( res . Response && res . Response . Error ) {
356
+ throw new TypeError (
357
+ 'API_SCF_CreateAlias' ,
358
+ JSON . stringify ( res . Response ) ,
359
+ null ,
360
+ res . Response . RequestId ,
361
+ ) ;
362
+ }
363
+ return res . Response ;
364
+ }
365
+
366
+ async updateAliasTraffic ( inputs ) {
367
+ const publishInputs = {
368
+ Action : 'UpdateAlias' ,
369
+ Version : '2018-04-16' ,
370
+ Region : inputs . region ,
371
+ FunctionName : inputs . functionName ,
372
+ FunctionVersion : inputs . functionVersion || '$LATEST' ,
373
+ Name : inputs . aliasName || '$DEFAULT' ,
374
+ Namespace : inputs . namespace || 'default' ,
375
+ RoutingConfig : {
376
+ AdditionalVersionWeights : [ { Version : inputs . lastVersion , Weight : 1 - inputs . traffic } ] ,
377
+ } ,
378
+ Description : inputs . description || 'Configured by Serverless Component' ,
379
+ } ;
380
+ const res = await this . scfClient . request ( publishInputs ) ;
381
+ if ( res . Response && res . Response . Error ) {
382
+ throw new TypeError (
383
+ 'API_SCF_UpdateAlias' ,
384
+ JSON . stringify ( res . Response ) ,
385
+ null ,
386
+ res . Response . RequestId ,
387
+ ) ;
388
+ }
389
+ return res . Response ;
390
+ }
391
+
315
392
// deploy SCF flow
316
393
async deploy ( inputs = { } ) {
317
394
// whether auto create/bind role
0 commit comments