11/* eslint-disable @aws-cdk/no-literal-partition */
22import * as fs from 'fs' ;
33import * as path from 'path' ;
4+ import { DescribeStackResourcesCommand , DescribeStacksCommand } from '@aws-sdk/client-cloudformation' ;
5+ import { DescribeRepositoriesCommand } from '@aws-sdk/client-ecr' ;
6+ import { CreatePolicyCommand , DeletePolicyCommand , GetRoleCommand } from '@aws-sdk/client-iam' ;
47import * as yaml from 'yaml' ;
58import { integTest , randomString , withoutBootstrap } from '../../lib' ;
69import eventually from '../../lib/eventually' ;
@@ -15,9 +18,11 @@ integTest('can bootstrap without execution', withoutBootstrap(async (fixture) =>
1518 noExecute : true ,
1619 } ) ;
1720
18- const resp = await fixture . aws . cloudFormation ( 'describeStacks' , {
19- StackName : bootstrapStackName ,
20- } ) ;
21+ const resp = await fixture . aws . cloudFormation . send (
22+ new DescribeStacksCommand ( {
23+ StackName : bootstrapStackName ,
24+ } ) ,
25+ ) ;
2126
2227 expect ( resp . Stacks ?. [ 0 ] . StackStatus ) . toEqual ( 'REVIEW_IN_PROGRESS' ) ;
2328} ) ) ;
@@ -145,7 +150,7 @@ integTest('can create a legacy bootstrap stack with --public-access-block-config
145150 tags : 'Foo=Bar' ,
146151 } ) ;
147152
148- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
153+ const response = await fixture . aws . cloudFormation . send ( new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ) ;
149154 expect ( response . Stacks ?. [ 0 ] . Tags ) . toEqual ( [
150155 { Key : 'Foo' , Value : 'Bar' } ,
151156 ] ) ;
@@ -167,7 +172,7 @@ integTest('can create multiple legacy bootstrap stacks', withoutBootstrap(async
167172 toolkitStackName : bootstrapStackName2 ,
168173 } ) ;
169174
170- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName1 } ) ;
175+ const response = await fixture . aws . cloudFormation . send ( new DescribeStacksCommand ( { StackName : bootstrapStackName1 } ) ) ;
171176 expect ( response . Stacks ?. [ 0 ] . Tags ) . toEqual ( [
172177 { Key : 'Foo' , Value : 'Bar' } ,
173178 ] ) ;
@@ -272,17 +277,19 @@ integTest('can remove customPermissionsBoundary', withoutBootstrap(async (fixtur
272277 const policyName = `${ bootstrapStackName } -pb` ;
273278 let policyArn ;
274279 try {
275- const policy = await fixture . aws . iam ( 'createPolicy' , {
276- PolicyName : policyName ,
277- PolicyDocument : JSON . stringify ( {
278- Version : '2012-10-17' ,
279- Statement : {
280- Action : [ '*' ] ,
281- Resource : [ '*' ] ,
282- Effect : 'Allow' ,
283- } ,
280+ const policy = await fixture . aws . iam . send (
281+ new CreatePolicyCommand ( {
282+ PolicyName : policyName ,
283+ PolicyDocument : JSON . stringify ( {
284+ Version : '2012-10-17' ,
285+ Statement : {
286+ Action : [ '*' ] ,
287+ Resource : [ '*' ] ,
288+ Effect : 'Allow' ,
289+ } ,
290+ } ) ,
284291 } ) ,
285- } ) ;
292+ ) ;
286293 policyArn = policy . Policy ?. Arn ;
287294
288295 // Policy creation and consistency across regions is "almost immediate"
@@ -295,7 +302,9 @@ integTest('can remove customPermissionsBoundary', withoutBootstrap(async (fixtur
295302 customPermissionsBoundary : policyName ,
296303 } ) ;
297304
298- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
305+ const response = await fixture . aws . cloudFormation . send (
306+ new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ,
307+ ) ;
299308 expect (
300309 response . Stacks ?. [ 0 ] . Parameters ?. some (
301310 param => ( param . ParameterKey === 'InputPermissionsBoundary' && param . ParameterValue === policyName ) ,
@@ -309,20 +318,27 @@ integTest('can remove customPermissionsBoundary', withoutBootstrap(async (fixtur
309318 toolkitStackName : bootstrapStackName ,
310319 usePreviousParameters : false ,
311320 } ) ;
312- const response2 = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
321+ const response2 = await fixture . aws . cloudFormation . send (
322+ new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ,
323+ ) ;
313324 expect (
314325 response2 . Stacks ?. [ 0 ] . Parameters ?. some (
315326 param => ( param . ParameterKey === 'InputPermissionsBoundary' && ! param . ParameterValue ) ,
316327 ) ) . toEqual ( true ) ;
317328
318329 const region = fixture . aws . region ;
319330 const account = await fixture . aws . account ( ) ;
320- const role = await fixture . aws . iam ( 'getRole' , { RoleName : `cdk-${ fixture . qualifier } -cfn-exec-role-${ account } -${ region } ` } ) ;
331+ const role = await fixture . aws . iam . send (
332+ new GetRoleCommand ( { RoleName : `cdk-${ fixture . qualifier } -cfn-exec-role-${ account } -${ region } ` } ) ,
333+ ) ;
334+ if ( ! role . Role ) {
335+ throw new Error ( 'Role not found' ) ;
336+ }
321337 expect ( role . Role . PermissionsBoundary ) . toBeUndefined ( ) ;
322338
323339 } finally {
324340 if ( policyArn ) {
325- await fixture . aws . iam ( 'deletePolicy' , { PolicyArn : policyArn } ) ;
341+ await fixture . aws . iam . send ( new DeletePolicyCommand ( { PolicyArn : policyArn } ) ) ;
326342 }
327343 }
328344} ) ) ;
@@ -342,7 +358,7 @@ integTest('switch on termination protection, switch is left alone on re-bootstra
342358 force : true ,
343359 } ) ;
344360
345- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
361+ const response = await fixture . aws . cloudFormation . send ( new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ) ;
346362 expect ( response . Stacks ?. [ 0 ] . EnableTerminationProtection ) . toEqual ( true ) ;
347363} ) ) ;
348364
@@ -361,7 +377,7 @@ integTest('add tags, left alone on re-bootstrap', withoutBootstrap(async (fixtur
361377 force : true ,
362378 } ) ;
363379
364- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
380+ const response = await fixture . aws . cloudFormation . send ( new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ) ;
365381 expect ( response . Stacks ?. [ 0 ] . Tags ) . toEqual ( [
366382 { Key : 'Foo' , Value : 'Bar' } ,
367383 ] ) ;
@@ -384,7 +400,7 @@ integTest('can add tags then update tags during re-bootstrap', withoutBootstrap(
384400 force : true ,
385401 } ) ;
386402
387- const response = await fixture . aws . cloudFormation ( 'describeStacks' , { StackName : bootstrapStackName } ) ;
403+ const response = await fixture . aws . cloudFormation . send ( new DescribeStacksCommand ( { StackName : bootstrapStackName } ) ) ;
388404 expect ( response . Stacks ?. [ 0 ] . Tags ) . toEqual ( [
389405 { Key : 'Foo' , Value : 'BarBaz' } ,
390406 ] ) ;
@@ -418,18 +434,22 @@ integTest('create ECR with tag IMMUTABILITY to set on', withoutBootstrap(async (
418434 toolkitStackName : bootstrapStackName ,
419435 } ) ;
420436
421- const response = await fixture . aws . cloudFormation ( 'describeStackResources' , {
422- StackName : bootstrapStackName ,
423- } ) ;
437+ const response = await fixture . aws . cloudFormation . send (
438+ new DescribeStackResourcesCommand ( {
439+ StackName : bootstrapStackName ,
440+ } ) ,
441+ ) ;
424442 const ecrResource = response . StackResources ?. find ( resource => resource . LogicalResourceId === 'ContainerAssetsRepository' ) ;
425443 expect ( ecrResource ) . toBeDefined ( ) ;
426444
427- const ecrResponse = await fixture . aws . ecr ( 'describeRepositories' , {
428- repositoryNames : [
429- // This is set, as otherwise we don't end up here
430- ecrResource ?. PhysicalResourceId ?? '' ,
431- ] ,
432- } ) ;
445+ const ecrResponse = await fixture . aws . ecr . send (
446+ new DescribeRepositoriesCommand ( {
447+ repositoryNames : [
448+ // This is set, as otherwise we don't end up here
449+ ecrResource ?. PhysicalResourceId ?? '' ,
450+ ] ,
451+ } ) ,
452+ ) ;
433453
434454 expect ( ecrResponse . repositories ?. [ 0 ] . imageTagMutability ) . toEqual ( 'IMMUTABLE' ) ;
435455} ) ) ;
0 commit comments