@@ -21,8 +21,51 @@ import { RuntimeFamily, getFamily } from '../../lambda/models/samLambdaRuntime'
21
21
import { showMessage } from '../../shared/utilities/messages'
22
22
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
23
23
import AdmZip from 'adm-zip'
24
- import { CloudFormation , Lambda } from 'aws-sdk'
24
+ import {
25
+ CloudFormationClient ,
26
+ CreateChangeSetCommand ,
27
+ CreateChangeSetInput ,
28
+ CreateChangeSetOutput ,
29
+ DescribeChangeSetCommand ,
30
+ DescribeChangeSetInput ,
31
+ DescribeChangeSetOutput ,
32
+ DescribeGeneratedTemplateCommand ,
33
+ DescribeGeneratedTemplateInput ,
34
+ DescribeGeneratedTemplateOutput ,
35
+ DescribeStackResourceCommand ,
36
+ DescribeStackResourceInput ,
37
+ DescribeStackResourceOutput ,
38
+ DescribeStackResourcesCommand ,
39
+ DescribeStackResourcesInput ,
40
+ DescribeStackResourcesOutput ,
41
+ DescribeStacksCommand ,
42
+ DescribeStacksInput ,
43
+ DescribeStacksOutput ,
44
+ ExecuteChangeSetCommand ,
45
+ ExecuteChangeSetInput ,
46
+ ExecuteChangeSetOutput ,
47
+ GetGeneratedTemplateCommand ,
48
+ GetGeneratedTemplateInput ,
49
+ GetGeneratedTemplateOutput ,
50
+ GetTemplateCommand ,
51
+ GetTemplateInput ,
52
+ GetTemplateOutput ,
53
+ waitUntilChangeSetCreateComplete ,
54
+ waitUntilStackImportComplete ,
55
+ waitUntilStackUpdateComplete ,
56
+ } from '@aws-sdk/client-cloudformation'
57
+ import {
58
+ FunctionConfiguration ,
59
+ FunctionUrlConfig ,
60
+ GetFunctionResponse ,
61
+ GetLayerVersionResponse ,
62
+ InvocationRequest ,
63
+ InvocationResponse ,
64
+ LayerVersionsListItem ,
65
+ Runtime ,
66
+ } from '@aws-sdk/client-lambda'
25
67
import { isAwsError , UnknownError } from '../../shared/errors'
68
+ import { WaiterConfiguration } from '@aws-sdk/types'
26
69
const localize = nls . loadMessageBundle ( )
27
70
28
71
/**
@@ -230,7 +273,7 @@ export class EnhancedLambdaClient {
230
273
}
231
274
}
232
275
233
- async invoke ( name : string , payload ?: Lambda . InvocationRequest [ 'Payload' ] ) : Promise < Lambda . InvocationResponse > {
276
+ async invoke ( name : string , payload ?: InvocationRequest [ 'Payload' ] ) : Promise < InvocationResponse > {
234
277
try {
235
278
return await this . client . invoke ( name , payload )
236
279
} catch ( error ) {
@@ -246,7 +289,7 @@ export class EnhancedLambdaClient {
246
289
}
247
290
}
248
291
249
- async * listFunctions ( ) : AsyncIterableIterator < Lambda . FunctionConfiguration > {
292
+ async * listFunctions ( ) : AsyncIterableIterator < FunctionConfiguration > {
250
293
try {
251
294
yield * this . client . listFunctions ( )
252
295
} catch ( error ) {
@@ -257,7 +300,7 @@ export class EnhancedLambdaClient {
257
300
}
258
301
}
259
302
260
- async getFunction ( name : string ) : Promise < Lambda . GetFunctionResponse > {
303
+ async getFunction ( name : string ) : Promise < GetFunctionResponse > {
261
304
try {
262
305
return await this . client . getFunction ( name )
263
306
} catch ( error ) {
@@ -273,7 +316,7 @@ export class EnhancedLambdaClient {
273
316
}
274
317
}
275
318
276
- async getLayerVersion ( name : string , version : number ) : Promise < Lambda . GetLayerVersionResponse > {
319
+ async getLayerVersion ( name : string , version : number ) : Promise < GetLayerVersionResponse > {
277
320
try {
278
321
return await this . client . getLayerVersion ( name , version )
279
322
} catch ( error ) {
@@ -289,7 +332,7 @@ export class EnhancedLambdaClient {
289
332
}
290
333
}
291
334
292
- async * listLayerVersions ( name : string ) : AsyncIterableIterator < Lambda . LayerVersionsListItem > {
335
+ async * listLayerVersions ( name : string ) : AsyncIterableIterator < LayerVersionsListItem > {
293
336
try {
294
337
yield * this . client . listLayerVersions ( name )
295
338
} catch ( error ) {
@@ -305,7 +348,7 @@ export class EnhancedLambdaClient {
305
348
}
306
349
}
307
350
308
- async getFunctionUrlConfigs ( name : string ) : Promise < Lambda . FunctionUrlConfigList > {
351
+ async getFunctionUrlConfigs ( name : string ) : Promise < FunctionUrlConfig [ ] > {
309
352
try {
310
353
return await this . client . getFunctionUrlConfigs ( name )
311
354
} catch ( error ) {
@@ -321,7 +364,7 @@ export class EnhancedLambdaClient {
321
364
}
322
365
}
323
366
324
- async updateFunctionCode ( name : string , zipFile : Uint8Array ) : Promise < Lambda . FunctionConfiguration > {
367
+ async updateFunctionCode ( name : string , zipFile : Uint8Array ) : Promise < FunctionConfiguration > {
325
368
try {
326
369
return await this . client . updateFunctionCode ( name , zipFile )
327
370
} catch ( error ) {
@@ -343,13 +386,13 @@ export class EnhancedLambdaClient {
343
386
*/
344
387
export class EnhancedCloudFormationClient {
345
388
constructor (
346
- private readonly client : CloudFormation ,
389
+ private readonly client : CloudFormationClient ,
347
390
private readonly regionCode : string
348
391
) { }
349
392
350
- async describeStacks ( params : CloudFormation . DescribeStacksInput ) : Promise < CloudFormation . DescribeStacksOutput > {
393
+ async describeStacks ( params : DescribeStacksInput ) : Promise < DescribeStacksOutput > {
351
394
try {
352
- return await this . client . describeStacks ( params ) . promise ( )
395
+ return await this . client . send ( new DescribeStacksCommand ( params ) )
353
396
} catch ( error ) {
354
397
if ( isPermissionError ( error ) ) {
355
398
const stackArn = params . StackName
@@ -361,9 +404,9 @@ export class EnhancedCloudFormationClient {
361
404
}
362
405
}
363
406
364
- async getTemplate ( params : CloudFormation . GetTemplateInput ) : Promise < CloudFormation . GetTemplateOutput > {
407
+ async getTemplate ( params : GetTemplateInput ) : Promise < GetTemplateOutput > {
365
408
try {
366
- return await this . client . getTemplate ( params ) . promise ( )
409
+ return await this . client . send ( new GetTemplateCommand ( params ) )
367
410
} catch ( error ) {
368
411
if ( isPermissionError ( error ) ) {
369
412
const stackArn = params . StackName
@@ -375,9 +418,9 @@ export class EnhancedCloudFormationClient {
375
418
}
376
419
}
377
420
378
- async createChangeSet ( params : CloudFormation . CreateChangeSetInput ) : Promise < CloudFormation . CreateChangeSetOutput > {
421
+ async createChangeSet ( params : CreateChangeSetInput ) : Promise < CreateChangeSetOutput > {
379
422
try {
380
- return await this . client . createChangeSet ( params ) . promise ( )
423
+ return await this . client . send ( new CreateChangeSetCommand ( params ) )
381
424
} catch ( error ) {
382
425
if ( isPermissionError ( error ) ) {
383
426
const stackArn = params . StackName
@@ -389,11 +432,9 @@ export class EnhancedCloudFormationClient {
389
432
}
390
433
}
391
434
392
- async executeChangeSet (
393
- params : CloudFormation . ExecuteChangeSetInput
394
- ) : Promise < CloudFormation . ExecuteChangeSetOutput > {
435
+ async executeChangeSet ( params : ExecuteChangeSetInput ) : Promise < ExecuteChangeSetOutput > {
395
436
try {
396
- return await this . client . executeChangeSet ( params ) . promise ( )
437
+ return await this . client . send ( new ExecuteChangeSetCommand ( params ) )
397
438
} catch ( error ) {
398
439
if ( isPermissionError ( error ) ) {
399
440
const stackArn = params . StackName
@@ -405,11 +446,9 @@ export class EnhancedCloudFormationClient {
405
446
}
406
447
}
407
448
408
- async describeChangeSet (
409
- params : CloudFormation . DescribeChangeSetInput
410
- ) : Promise < CloudFormation . DescribeChangeSetOutput > {
449
+ async describeChangeSet ( params : DescribeChangeSetInput ) : Promise < DescribeChangeSetOutput > {
411
450
try {
412
- return await this . client . describeChangeSet ( params ) . promise ( )
451
+ return await this . client . send ( new DescribeChangeSetCommand ( params ) )
413
452
} catch ( error ) {
414
453
if ( isPermissionError ( error ) ) {
415
454
const stackArn = params . StackName
@@ -421,11 +460,9 @@ export class EnhancedCloudFormationClient {
421
460
}
422
461
}
423
462
424
- async describeStackResources (
425
- params : CloudFormation . DescribeStackResourcesInput
426
- ) : Promise < CloudFormation . DescribeStackResourcesOutput > {
463
+ async describeStackResources ( params : DescribeStackResourcesInput ) : Promise < DescribeStackResourcesOutput > {
427
464
try {
428
- return await this . client . describeStackResources ( params ) . promise ( )
465
+ return await this . client . send ( new DescribeStackResourcesCommand ( params ) )
429
466
} catch ( error ) {
430
467
if ( isPermissionError ( error ) ) {
431
468
const stackArn = params . StackName
@@ -437,11 +474,9 @@ export class EnhancedCloudFormationClient {
437
474
}
438
475
}
439
476
440
- async describeStackResource (
441
- params : CloudFormation . DescribeStackResourceInput
442
- ) : Promise < CloudFormation . DescribeStackResourceOutput > {
477
+ async describeStackResource ( params : DescribeStackResourceInput ) : Promise < DescribeStackResourceOutput > {
443
478
try {
444
- return await this . client . describeStackResource ( params ) . promise ( )
479
+ return await this . client . send ( new DescribeStackResourceCommand ( params ) )
445
480
} catch ( error ) {
446
481
if ( isPermissionError ( error ) ) {
447
482
const stackArn = params . StackName
@@ -453,11 +488,9 @@ export class EnhancedCloudFormationClient {
453
488
}
454
489
}
455
490
456
- async getGeneratedTemplate (
457
- params : CloudFormation . GetGeneratedTemplateInput
458
- ) : Promise < CloudFormation . GetGeneratedTemplateOutput > {
491
+ async getGeneratedTemplate ( params : GetGeneratedTemplateInput ) : Promise < GetGeneratedTemplateOutput > {
459
492
try {
460
- return await this . client . getGeneratedTemplate ( params ) . promise ( )
493
+ return await this . client . send ( new GetGeneratedTemplateCommand ( params ) )
461
494
} catch ( error ) {
462
495
if ( isPermissionError ( error ) ) {
463
496
throw createEnhancedPermissionError ( error , 'cloudformation' , 'getGeneratedTemplate' )
@@ -466,11 +499,9 @@ export class EnhancedCloudFormationClient {
466
499
}
467
500
}
468
501
469
- async describeGeneratedTemplate (
470
- params : CloudFormation . DescribeGeneratedTemplateInput
471
- ) : Promise < CloudFormation . DescribeGeneratedTemplateOutput > {
502
+ async describeGeneratedTemplate ( params : DescribeGeneratedTemplateInput ) : Promise < DescribeGeneratedTemplateOutput > {
472
503
try {
473
- return await this . client . describeGeneratedTemplate ( params ) . promise ( )
504
+ return await this . client . send ( new DescribeGeneratedTemplateCommand ( params ) )
474
505
} catch ( error ) {
475
506
if ( isPermissionError ( error ) ) {
476
507
throw createEnhancedPermissionError ( error , 'cloudformation' , 'describeGeneratedTemplate' )
@@ -481,7 +512,20 @@ export class EnhancedCloudFormationClient {
481
512
482
513
async waitFor ( state : string , params : any ) : Promise < any > {
483
514
try {
484
- return await this . client . waitFor ( state as any , params ) . promise ( )
515
+ const waiterConfig = {
516
+ client : this . client ,
517
+ maxWaitTime : 900 ,
518
+ } satisfies WaiterConfiguration < CloudFormationClient >
519
+ switch ( state ) {
520
+ case 'changeSetCreateComplete' :
521
+ return await waitUntilChangeSetCreateComplete ( waiterConfig , params )
522
+ case 'stackImportComplete' :
523
+ return await waitUntilStackImportComplete ( waiterConfig , params )
524
+ case 'stackUpdateComplete' :
525
+ return await waitUntilStackUpdateComplete ( waiterConfig , params )
526
+ default :
527
+ throw new Error ( `Unsupported waiter state: ${ state } ` )
528
+ }
485
529
} catch ( error ) {
486
530
if ( isPermissionError ( error ) ) {
487
531
// For waitFor operations, we'll provide a generic permission error since the specific action varies
@@ -560,7 +604,7 @@ export async function getLambdaHandlerFile(
560
604
folderUri : vscode . Uri ,
561
605
codeUri : string ,
562
606
handler : string ,
563
- runtime : string
607
+ runtime : Runtime
564
608
) : Promise < vscode . Uri | undefined > {
565
609
const family = getFamily ( runtime )
566
610
if ( ! supportedRuntimeForHandler . has ( family ) ) {
@@ -704,6 +748,9 @@ export function getLambdaClient(region: string): EnhancedLambdaClient {
704
748
}
705
749
706
750
export async function getCFNClient ( regionCode : string ) : Promise < EnhancedCloudFormationClient > {
707
- const originalClient = await globals . sdkClientBuilder . createAwsService ( CloudFormation , { } , regionCode )
751
+ const originalClient = globals . sdkClientBuilderV3 . createAwsService ( {
752
+ serviceClient : CloudFormationClient ,
753
+ region : regionCode ,
754
+ } )
708
755
return new EnhancedCloudFormationClient ( originalClient , regionCode )
709
756
}
0 commit comments