@@ -29,14 +29,14 @@ import {
2929 testSshConnection ,
3030} from '../../shared/extensions/ssh'
3131import { getLogger } from '../../shared/logger/logger'
32- import { CancellationError , Timeout } from '../../shared/utilities/timeoutUtils'
32+ import { CancellationError , Timeout , waitUntil } from '../../shared/utilities/timeoutUtils'
3333import { showMessageWithCancel } from '../../shared/utilities/messages'
3434import { SshConfig } from '../../shared/sshConfig'
3535import { SshKeyPair } from './sshKeyPair'
3636import { Ec2SessionTracker } from './remoteSessionManager'
3737import { getEc2SsmEnv } from './utils'
3838
39- export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect ' | 'EC2SSMAgentStatus'
39+ export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMTestConnect ' | 'EC2SSMAgentStatus'
4040
4141export interface Ec2RemoteEnv extends VscodeRemoteConnection {
4242 selection : Ec2Selection
@@ -150,8 +150,14 @@ export class Ec2Connecter implements vscode.Disposable {
150150 }
151151 }
152152
153- private async checkForInstanceSsmError ( selection : Ec2Selection ) : Promise < void > {
154- const isSsmAgentRunning = ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
153+ public async checkForInstanceSsmError (
154+ selection : Ec2Selection ,
155+ options ?: Partial < { interval : number ; timeout : number } >
156+ ) : Promise < void > {
157+ const isSsmAgentRunning = await waitUntil (
158+ async ( ) => ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online' ,
159+ { interval : options ?. interval ?? 500 , timeout : options ?. timeout ?? 5000 }
160+ )
155161
156162 if ( ! isSsmAgentRunning ) {
157163 this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
@@ -215,8 +221,8 @@ export class Ec2Connecter implements vscode.Disposable {
215221 remoteUser . name
216222 )
217223 } catch ( err ) {
218- const message = err instanceof SshError ? ' Testing SSH connection to instance failed' : ''
219- this . throwConnectionError ( message , selection , err as Error )
224+ const message = err instanceof SshError ? ` Testing SSM connection to instance failed: ${ err . message } ` : ''
225+ this . throwConnectionError ( message , selection , { ... ( err as Error ) , code : 'EC2SSMTestConnect' } )
220226 } finally {
221227 await this . ssmClient . terminateSession ( testSession )
222228 }
0 commit comments