@@ -11,7 +11,7 @@ import { IPackageSource } from './package-sources/source';
11
11
import { packageSourceInSubprocess } from './package-sources/subprocess' ;
12
12
import { RESOURCES_DIR } from './resources' ;
13
13
import { shell , ShellOptions , ShellHelper , rimraf } from './shell' ;
14
- import { AwsContext , withAws } from './with-aws' ;
14
+ import { AwsContext , atmosphereEnabled , withAws } from './with-aws' ;
15
15
import { withTimeout } from './with-timeout' ;
16
16
17
17
export const DEFAULT_TEST_TIMEOUT_S = 20 * 60 ;
@@ -498,13 +498,22 @@ export class TestFixture extends ShellHelper {
498
498
499
499
await this . packages . makeCliAvailable ( ) ;
500
500
501
+ // if tests are using an explicit aws identity already (i.e creds)
502
+ // force every cdk command to use the same identity.
503
+ const awsCreds : Record < string , string > = this . aws . identity ? {
504
+ AWS_ACCESS_KEY_ID : this . aws . identity . accessKeyId ,
505
+ AWS_SECRET_ACCESS_KEY : this . aws . identity . secretAccessKey ,
506
+ AWS_SESSION_TOKEN : this . aws . identity . sessionToken ! ,
507
+ } : { } ;
508
+
501
509
return this . shell ( [ 'cdk' , ...( verbose ? [ '-v' ] : [ ] ) , ...args ] , {
502
510
...options ,
503
511
modEnv : {
504
512
AWS_REGION : this . aws . region ,
505
513
AWS_DEFAULT_REGION : this . aws . region ,
506
514
STACK_NAME_PREFIX : this . stackNamePrefix ,
507
515
PACKAGE_LAYOUT_VERSION : this . packages . majorVersion ( ) ,
516
+ ...awsCreds ,
508
517
...options . modEnv ,
509
518
} ,
510
519
} ) ;
@@ -555,37 +564,44 @@ export class TestFixture extends ShellHelper {
555
564
* Cleanup leftover stacks and bootstrapped resources
556
565
*/
557
566
public async dispose ( success : boolean ) {
558
- const stacksToDelete = await this . deleteableStacks ( this . stackNamePrefix ) ;
559
-
560
- this . sortBootstrapStacksToTheEnd ( stacksToDelete ) ;
561
-
562
- // Bootstrap stacks have buckets that need to be cleaned
563
- const bucketNames = stacksToDelete . map ( stack => outputFromStack ( 'BucketName' , stack ) ) . filter ( defined ) ;
564
- // Parallelism will be reasonable
565
- // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
566
- await Promise . all ( bucketNames . map ( b => this . aws . emptyBucket ( b ) ) ) ;
567
- // The bootstrap bucket has a removal policy of RETAIN by default, so add it to the buckets to be cleaned up.
568
- this . bucketsToDelete . push ( ...bucketNames ) ;
569
-
570
- // Bootstrap stacks have ECR repositories with images which should be deleted
571
- const imageRepositoryNames = stacksToDelete . map ( stack => outputFromStack ( 'ImageRepositoryName' , stack ) ) . filter ( defined ) ;
572
- // Parallelism will be reasonable
573
- // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
574
- await Promise . all ( imageRepositoryNames . map ( r => this . aws . deleteImageRepository ( r ) ) ) ;
575
-
576
- await this . aws . deleteStacks (
577
- ...stacksToDelete . map ( ( s ) => {
578
- if ( ! s . StackName ) {
579
- throw new Error ( 'Stack name is required to delete a stack.' ) ;
580
- }
581
- return s . StackName ;
582
- } ) ,
583
- ) ;
584
567
585
- // We might have leaked some buckets by upgrading the bootstrap stack. Be
586
- // sure to clean everything.
587
- for ( const bucket of this . bucketsToDelete ) {
588
- await this . aws . deleteBucket ( bucket ) ;
568
+ // when using the atmosphere service, it does resource cleanup on our behalf
569
+ // so we don't have to wait for it.
570
+ if ( ! atmosphereEnabled ( ) ) {
571
+
572
+ const stacksToDelete = await this . deleteableStacks ( this . stackNamePrefix ) ;
573
+
574
+ this . sortBootstrapStacksToTheEnd ( stacksToDelete ) ;
575
+
576
+ // Bootstrap stacks have buckets that need to be cleaned
577
+ const bucketNames = stacksToDelete . map ( stack => outputFromStack ( 'BucketName' , stack ) ) . filter ( defined ) ;
578
+ // Parallelism will be reasonable
579
+ // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
580
+ await Promise . all ( bucketNames . map ( b => this . aws . emptyBucket ( b ) ) ) ;
581
+ // The bootstrap bucket has a removal policy of RETAIN by default, so add it to the buckets to be cleaned up.
582
+ this . bucketsToDelete . push ( ...bucketNames ) ;
583
+
584
+ // Bootstrap stacks have ECR repositories with images which should be deleted
585
+ const imageRepositoryNames = stacksToDelete . map ( stack => outputFromStack ( 'ImageRepositoryName' , stack ) ) . filter ( defined ) ;
586
+ // Parallelism will be reasonable
587
+ // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
588
+ await Promise . all ( imageRepositoryNames . map ( r => this . aws . deleteImageRepository ( r ) ) ) ;
589
+
590
+ await this . aws . deleteStacks (
591
+ ...stacksToDelete . map ( ( s ) => {
592
+ if ( ! s . StackName ) {
593
+ throw new Error ( 'Stack name is required to delete a stack.' ) ;
594
+ }
595
+ return s . StackName ;
596
+ } ) ,
597
+ ) ;
598
+
599
+ // We might have leaked some buckets by upgrading the bootstrap stack. Be
600
+ // sure to clean everything.
601
+ for ( const bucket of this . bucketsToDelete ) {
602
+ await this . aws . deleteBucket ( bucket ) ;
603
+ }
604
+
589
605
}
590
606
591
607
// If the tests completed successfully, happily delete the fixture
@@ -662,7 +678,11 @@ export async function ensureBootstrapped(fixture: TestFixture) {
662
678
} ,
663
679
} ) ;
664
680
665
- ALREADY_BOOTSTRAPPED_IN_THIS_RUN . add ( envSpecifier ) ;
681
+ // when using the atmosphere service, every test needs to bootstrap
682
+ // its own environment.
683
+ if ( ! atmosphereEnabled ( ) ) {
684
+ ALREADY_BOOTSTRAPPED_IN_THIS_RUN . add ( envSpecifier ) ;
685
+ }
666
686
}
667
687
668
688
function defined < A > ( x : A ) : x is NonNullable < A > {
0 commit comments