@@ -57,21 +57,27 @@ public async Task InitializeAsync()
5757 return ;
5858 }
5959
60- // Create LocalStack container
61- _localStackContainer = new ContainerBuilder ( )
62- . WithImage ( "localstack/localstack:latest" )
63- . WithPortBinding ( 4566 , 4566 )
64- . WithEnvironment ( "SERVICES" , "sqs,sns,kms" )
65- . WithEnvironment ( "DEBUG" , "1" )
66- . WithEnvironment ( "DATA_DIR" , "/tmp/localstack/data" )
67- . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilPortIsAvailable ( 4566 ) )
68- . Build ( ) ;
69-
70- // Start LocalStack
71- await _localStackContainer . StartAsync ( ) ;
72-
73- // Wait a bit for services to be ready
74- await Task . Delay ( 2000 ) ;
60+ // Check if LocalStack is already running (e.g., in GitHub Actions)
61+ bool isAlreadyRunning = await _configuration . IsLocalStackAvailableAsync ( TimeSpan . FromSeconds ( 2 ) ) ;
62+
63+ if ( ! isAlreadyRunning )
64+ {
65+ // Create LocalStack container
66+ _localStackContainer = new ContainerBuilder ( )
67+ . WithImage ( "localstack/localstack:latest" )
68+ . WithPortBinding ( 4566 , 4566 )
69+ . WithEnvironment ( "SERVICES" , "sqs,sns,kms" )
70+ . WithEnvironment ( "DEBUG" , "1" )
71+ . WithEnvironment ( "DATA_DIR" , "/tmp/localstack/data" )
72+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilPortIsAvailable ( 4566 ) )
73+ . Build ( ) ;
74+
75+ // Start LocalStack
76+ await _localStackContainer . StartAsync ( ) ;
77+
78+ // Wait a bit for services to be ready
79+ await Task . Delay ( 2000 ) ;
80+ }
7581
7682 // Create AWS clients configured for LocalStack
7783 var config = new Amazon . SQS . AmazonSQSConfig
@@ -114,6 +120,7 @@ public async Task DisposeAsync()
114120 SnsClient ? . Dispose ( ) ;
115121 KmsClient ? . Dispose ( ) ;
116122
123+ // Only stop container if we started it
117124 if ( _localStackContainer != null )
118125 {
119126 await _localStackContainer . StopAsync ( ) ;
0 commit comments