@@ -292,20 +292,23 @@ export function installCdkTarball(projectPath: string): void {
292292}
293293
294294export async function teardownE2EProject ( projectPath : string , agentName : string , modelProvider : string ) : Promise < void > {
295- await spawnAndCollect ( 'agentcore' , [ 'remove' , 'all' , '--json' ] , projectPath ) ;
296- const result = await spawnAndCollect ( 'agentcore' , [ 'deploy' , '--yes' , '--json' ] , projectPath ) ;
297- if ( result . exitCode !== 0 ) {
298- console . log ( 'Teardown stdout:' , result . stdout ) ;
299- console . log ( 'Teardown stderr:' , result . stderr ) ;
300- }
295+ // Delete credential provider first — it's not a CFN resource, so deleting it
296+ // before stack teardown is safe and avoids leaking providers when stack
297+ // destruction times out or fails.
301298 if ( modelProvider !== 'Bedrock' && agentName ) {
302299 const providerName = `${ agentName } ${ modelProvider } ` ;
303300 const region = process . env . AWS_REGION ?? 'us-east-1' ;
304301 try {
305302 const client = new BedrockAgentCoreControlClient ( { region } ) ;
306303 await client . send ( new DeleteApiKeyCredentialProviderCommand ( { name : providerName } ) ) ;
307- } catch {
308- // Best-effort cleanup
304+ } catch ( err ) {
305+ console . warn ( `Failed to delete credential provider ${ providerName } :` , err ) ;
309306 }
310307 }
308+ await spawnAndCollect ( 'agentcore' , [ 'remove' , 'all' , '--json' ] , projectPath ) ;
309+ const result = await spawnAndCollect ( 'agentcore' , [ 'deploy' , '--yes' , '--json' ] , projectPath ) ;
310+ if ( result . exitCode !== 0 ) {
311+ console . log ( 'Teardown stdout:' , result . stdout ) ;
312+ console . log ( 'Teardown stderr:' , result . stderr ) ;
313+ }
311314}
0 commit comments