@@ -20,7 +20,12 @@ import {
2020} from '../../shared/remoteSession'
2121import { DefaultIamClient } from '../../shared/clients/iamClient'
2222import { ErrorInformation } from '../../shared/errors'
23- import { sshAgentSocketVariable , startSshAgent , startVscodeRemote } from '../../shared/extensions/ssh'
23+ import {
24+ sshAgentSocketVariable ,
25+ startSshAgent ,
26+ startVscodeRemote ,
27+ testSshConnection ,
28+ } from '../../shared/extensions/ssh'
2429import { createBoundProcess } from '../../codecatalyst/model'
2530import { getLogger } from '../../shared/logger/logger'
2631import { CancellationError , Timeout } from '../../shared/utilities/timeoutUtils'
@@ -195,6 +200,7 @@ export class Ec2Connecter implements vscode.Disposable {
195200 const remoteEnv = await this . prepareEc2RemoteEnvWithProgress ( selection , remoteUser )
196201
197202 try {
203+ await testSshConnection ( remoteEnv . sshPath , remoteEnv . hostname )
198204 await startVscodeRemote ( remoteEnv . SessionProcess , remoteEnv . hostname , '/' , remoteEnv . vscPath , remoteUser )
199205 } catch ( err ) {
200206 this . throwGeneralConnectionError ( selection , err as Error )
@@ -212,8 +218,9 @@ export class Ec2Connecter implements vscode.Disposable {
212218 const logger = this . configureRemoteConnectionLogger ( selection . instanceId )
213219 const { ssm, vsc, ssh } = ( await ensureDependencies ( ) ) . unwrap ( )
214220 const keyPair = await this . configureSshKeys ( selection , remoteUser )
215- const hostNamePrefix = 'aws-ec2-'
216- const sshConfig = new SshConfig ( ssh , hostNamePrefix , 'ec2_connect' , keyPair . getPrivateKeyPath ( ) )
221+ const hostnamePrefix = 'aws-ec2-'
222+ const hostname = `${ hostnamePrefix } ${ selection . instanceId } `
223+ const sshConfig = new SshConfig ( ssh , hostnamePrefix , 'ec2_connect' , keyPair . getPrivateKeyPath ( ) )
217224
218225 const config = await sshConfig . ensureValid ( )
219226 if ( config . isErr ( ) ) {
@@ -222,6 +229,7 @@ export class Ec2Connecter implements vscode.Disposable {
222229
223230 throw err
224231 }
232+
225233 const ssmSession = await this . ssmClient . startSession ( selection . instanceId , 'AWS-StartSSHSession' )
226234 await this . addActiveSession ( selection . instanceId , ssmSession . SessionId ! )
227235
@@ -236,7 +244,7 @@ export class Ec2Connecter implements vscode.Disposable {
236244 } )
237245
238246 return {
239- hostname : ` ${ hostNamePrefix } ${ selection . instanceId } ` ,
247+ hostname,
240248 envProvider,
241249 sshPath : ssh ,
242250 vscPath : vsc ,
0 commit comments