@@ -29,14 +29,14 @@ import {
29
29
testSshConnection ,
30
30
} from '../../shared/extensions/ssh'
31
31
import { getLogger } from '../../shared/logger/logger'
32
- import { CancellationError , Timeout } from '../../shared/utilities/timeoutUtils'
32
+ import { CancellationError , Timeout , waitUntil } from '../../shared/utilities/timeoutUtils'
33
33
import { showMessageWithCancel } from '../../shared/utilities/messages'
34
34
import { SshConfig } from '../../shared/sshConfig'
35
35
import { SshKeyPair } from './sshKeyPair'
36
36
import { Ec2SessionTracker } from './remoteSessionManager'
37
37
import { getEc2SsmEnv } from './utils'
38
38
39
- export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect ' | 'EC2SSMAgentStatus'
39
+ export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMTestConnect ' | 'EC2SSMAgentStatus'
40
40
41
41
export interface Ec2RemoteEnv extends VscodeRemoteConnection {
42
42
selection : Ec2Selection
@@ -150,8 +150,14 @@ export class Ec2Connecter implements vscode.Disposable {
150
150
}
151
151
}
152
152
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
+ )
155
161
156
162
if ( ! isSsmAgentRunning ) {
157
163
this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
@@ -215,8 +221,8 @@ export class Ec2Connecter implements vscode.Disposable {
215
221
remoteUser . name
216
222
)
217
223
} 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' } )
220
226
} finally {
221
227
await this . ssmClient . terminateSession ( testSession )
222
228
}
0 commit comments