33 * SPDX-License-Identifier: Apache-2.0
44 */
55import * as vscode from 'vscode'
6- import { Session } from 'aws-sdk/clients/ssm'
7- import { EC2 , IAM , SSM } from 'aws-sdk'
6+ import { EC2 , IAM } from 'aws-sdk'
87import { Ec2Selection } from './prompter'
98import { getOrInstallCli } from '../../shared/utilities/cliUtils'
109import { isCloud9 } from '../../shared/extensionUtilities'
1110import { ToolkitError } from '../../shared/errors'
12- import { SsmClient } from '../../shared/clients/ssmClient '
11+ import { SsmClient } from '../../shared/clients/ssm '
1312import { Ec2Client } from '../../shared/clients/ec2Client'
1413import {
1514 VscodeRemoteConnection ,
@@ -35,13 +34,14 @@ import { SshConfig } from '../../shared/sshConfig'
3534import { SshKeyPair } from './sshKeyPair'
3635import { Ec2SessionTracker } from './remoteSessionManager'
3736import { getEc2SsmEnv } from './utils'
37+ import { Session , StartSessionResponse } from '@aws-sdk/client-ssm'
3838
3939export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect' | 'EC2SSMAgentStatus'
4040
4141export interface Ec2RemoteEnv extends VscodeRemoteConnection {
4242 selection : Ec2Selection
4343 keyPair : SshKeyPair
44- ssmSession : SSM . StartSessionResponse
44+ ssmSession : StartSessionResponse
4545}
4646
4747export type Ec2OS = 'Amazon Linux' | 'Ubuntu' | 'macOS'
@@ -51,7 +51,7 @@ interface RemoteUser {
5151}
5252
5353export class Ec2Connecter implements vscode . Disposable {
54- protected ssmClient : SsmClient
54+ protected ssm : SsmClient
5555 protected ec2Client : Ec2Client
5656 protected iamClient : DefaultIamClient
5757 protected sessionManager : Ec2SessionTracker
@@ -65,10 +65,10 @@ export class Ec2Connecter implements vscode.Disposable {
6565 )
6666
6767 public constructor ( readonly regionCode : string ) {
68- this . ssmClient = this . createSsmSdkClient ( )
68+ this . ssm = this . createSsmSdkClient ( )
6969 this . ec2Client = this . createEc2SdkClient ( )
7070 this . iamClient = this . createIamSdkClient ( )
71- this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssmClient )
71+ this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssm )
7272 }
7373
7474 protected createSsmSdkClient ( ) : SsmClient {
@@ -83,7 +83,7 @@ export class Ec2Connecter implements vscode.Disposable {
8383 return new DefaultIamClient ( this . regionCode )
8484 }
8585
86- public async addActiveSession ( sessionId : SSM . SessionId , instanceId : EC2 . InstanceId ) : Promise < void > {
86+ public async addActiveSession ( sessionId : string , instanceId : EC2 . InstanceId ) : Promise < void > {
8787 await this . sessionManager . addSession ( instanceId , sessionId )
8888 }
8989
@@ -151,7 +151,7 @@ export class Ec2Connecter implements vscode.Disposable {
151151 }
152152
153153 private async checkForInstanceSsmError ( selection : Ec2Selection ) : Promise < void > {
154- const isSsmAgentRunning = ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
154+ const isSsmAgentRunning = ( await this . ssm . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
155155
156156 if ( ! isSsmAgentRunning ) {
157157 this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
@@ -178,15 +178,15 @@ export class Ec2Connecter implements vscode.Disposable {
178178 shellArgs : shellArgs ,
179179 }
180180
181- await openRemoteTerminal ( terminalOptions , ( ) => this . ssmClient . terminateSession ( session ) ) . catch ( ( err ) => {
181+ await openRemoteTerminal ( terminalOptions , ( ) => this . ssm . terminateSession ( session ) ) . catch ( ( err ) => {
182182 throw ToolkitError . chain ( err , 'Failed to open ec2 instance.' )
183183 } )
184184 }
185185
186186 public async attemptToOpenEc2Terminal ( selection : Ec2Selection ) : Promise < void > {
187187 await this . checkForStartSessionError ( selection )
188188 try {
189- const response = await this . ssmClient . startSession ( selection . instanceId )
189+ const response = await this . ssm . startSession ( selection . instanceId )
190190 await this . openSessionInTerminal ( response , selection )
191191 } catch ( err : unknown ) {
192192 this . throwConnectionError ( '' , selection , err as Error )
@@ -198,7 +198,7 @@ export class Ec2Connecter implements vscode.Disposable {
198198
199199 const remoteUser = await this . getRemoteUser ( selection . instanceId )
200200 const remoteEnv = await this . prepareEc2RemoteEnvWithProgress ( selection , remoteUser )
201- const testSession = await this . ssmClient . startSession ( selection . instanceId , 'AWS-StartSSHSession' )
201+ const testSession = await this . ssm . startSession ( selection . instanceId , 'AWS-StartSSHSession' )
202202 try {
203203 await testSshConnection (
204204 remoteEnv . SessionProcess ,
@@ -218,7 +218,7 @@ export class Ec2Connecter implements vscode.Disposable {
218218 const message = err instanceof SshError ? 'Testing SSH connection to instance failed' : ''
219219 this . throwConnectionError ( message , selection , err as Error )
220220 } finally {
221- await this . ssmClient . terminateSession ( testSession )
221+ await this . ssm . terminateSession ( testSession )
222222 }
223223 }
224224
@@ -232,8 +232,8 @@ export class Ec2Connecter implements vscode.Disposable {
232232 return remoteEnv
233233 }
234234
235- private async startSSMSession ( instanceId : string ) : Promise < SSM . StartSessionResponse > {
236- const ssmSession = await this . ssmClient . startSession ( instanceId , 'AWS-StartSSHSession' )
235+ private async startSSMSession ( instanceId : string ) : Promise < StartSessionResponse > {
236+ const ssmSession = await this . ssm . startSession ( instanceId , 'AWS-StartSSHSession' )
237237 await this . addActiveSession ( instanceId , ssmSession . SessionId ! )
238238 return ssmSession
239239 }
@@ -308,7 +308,7 @@ export class Ec2Connecter implements vscode.Disposable {
308308 }
309309
310310 private async sendCommandAndWait ( instanceId : string , command : string ) {
311- return await this . ssmClient . sendCommandAndWait ( instanceId , 'AWS-RunShellScript' , {
311+ return await this . ssm . sendCommandAndWait ( instanceId , 'AWS-RunShellScript' , {
312312 commands : [ command ] ,
313313 } )
314314 }
@@ -331,7 +331,7 @@ export class Ec2Connecter implements vscode.Disposable {
331331 }
332332
333333 public async getRemoteUser ( instanceId : string ) : Promise < RemoteUser > {
334- const os = await this . ssmClient . getTargetPlatformName ( instanceId )
334+ const os = await this . ssm . getTargetPlatformName ( instanceId )
335335 if ( os === 'Amazon Linux' ) {
336336 return { name : 'ec2-user' , os }
337337 }
0 commit comments