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 { SSMWrapper } from '../../shared/clients/ssm '
1312import { Ec2Client } from '../../shared/clients/ec2Client'
1413import {
1514 VscodeRemoteConnection ,
@@ -29,17 +28,18 @@ import { SshConfig } from '../../shared/sshConfig'
2928import { SshKeyPair } from './sshKeyPair'
3029import { Ec2SessionTracker } from './remoteSessionManager'
3130import { getEc2SsmEnv } from './utils'
31+ import { Session , StartSessionCommandOutput } from '@aws-sdk/client-ssm'
3232
3333export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect' | 'EC2SSMAgentStatus'
3434
3535export interface Ec2RemoteEnv extends VscodeRemoteConnection {
3636 selection : Ec2Selection
3737 keyPair : SshKeyPair
38- ssmSession : SSM . StartSessionResponse
38+ ssmSession : StartSessionCommandOutput
3939}
4040
4141export class Ec2Connecter implements vscode . Disposable {
42- protected ssmClient : SsmClient
42+ protected ssm : SSMWrapper
4343 protected ec2Client : Ec2Client
4444 protected iamClient : DefaultIamClient
4545 protected sessionManager : Ec2SessionTracker
@@ -53,14 +53,14 @@ export class Ec2Connecter implements vscode.Disposable {
5353 )
5454
5555 public constructor ( readonly regionCode : string ) {
56- this . ssmClient = this . createSsmSdkClient ( )
56+ this . ssm = this . createSsmSdkClient ( )
5757 this . ec2Client = this . createEc2SdkClient ( )
5858 this . iamClient = this . createIamSdkClient ( )
59- this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssmClient )
59+ this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssm )
6060 }
6161
62- protected createSsmSdkClient ( ) : SsmClient {
63- return new SsmClient ( this . regionCode )
62+ protected createSsmSdkClient ( ) : SSMWrapper {
63+ return new SSMWrapper ( this . regionCode )
6464 }
6565
6666 protected createEc2SdkClient ( ) : Ec2Client {
@@ -71,7 +71,7 @@ export class Ec2Connecter implements vscode.Disposable {
7171 return new DefaultIamClient ( this . regionCode )
7272 }
7373
74- public async addActiveSession ( sessionId : SSM . SessionId , instanceId : EC2 . InstanceId ) : Promise < void > {
74+ public async addActiveSession ( sessionId : string , instanceId : EC2 . InstanceId ) : Promise < void > {
7575 await this . sessionManager . addSession ( instanceId , sessionId )
7676 }
7777
@@ -139,7 +139,7 @@ export class Ec2Connecter implements vscode.Disposable {
139139 }
140140
141141 private async checkForInstanceSsmError ( selection : Ec2Selection ) : Promise < void > {
142- const isSsmAgentRunning = ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
142+ const isSsmAgentRunning = ( await this . ssm . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
143143
144144 if ( ! isSsmAgentRunning ) {
145145 this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
@@ -173,15 +173,15 @@ export class Ec2Connecter implements vscode.Disposable {
173173 shellArgs : shellArgs ,
174174 }
175175
176- await openRemoteTerminal ( terminalOptions , ( ) => this . ssmClient . terminateSession ( session ) ) . catch ( ( err ) => {
176+ await openRemoteTerminal ( terminalOptions , ( ) => this . ssm . terminateSession ( session ) ) . catch ( ( err ) => {
177177 throw ToolkitError . chain ( err , 'Failed to open ec2 instance.' )
178178 } )
179179 }
180180
181181 public async attemptToOpenEc2Terminal ( selection : Ec2Selection ) : Promise < void > {
182182 await this . checkForStartSessionError ( selection )
183183 try {
184- const response = await this . ssmClient . startSession ( selection . instanceId )
184+ const response = await this . ssm . startSession ( selection . instanceId )
185185 await this . openSessionInTerminal ( response , selection )
186186 } catch ( err : unknown ) {
187187 this . throwGeneralConnectionError ( selection , err as Error )
@@ -222,7 +222,7 @@ export class Ec2Connecter implements vscode.Disposable {
222222
223223 throw err
224224 }
225- const ssmSession = await this . ssmClient . startSession ( selection . instanceId , 'AWS-StartSSHSession' )
225+ const ssmSession = await this . ssm . startSession ( selection . instanceId , 'AWS-StartSSHSession' )
226226 await this . addActiveSession ( selection . instanceId , ssmSession . SessionId ! )
227227
228228 const vars = getEc2SsmEnv ( selection , ssm , ssmSession )
@@ -270,13 +270,13 @@ export class Ec2Connecter implements vscode.Disposable {
270270 const command = `echo "${ sshPubKey } " > ${ remoteAuthorizedKeysPaths } `
271271 const documentName = 'AWS-RunShellScript'
272272
273- await this . ssmClient . sendCommandAndWait ( selection . instanceId , documentName , {
273+ await this . ssm . sendCommandAndWait ( selection . instanceId , documentName , {
274274 commands : [ command ] ,
275275 } )
276276 }
277277
278278 public async getRemoteUser ( instanceId : string ) {
279- const osName = await this . ssmClient . getTargetPlatformName ( instanceId )
279+ const osName = await this . ssm . getTargetPlatformName ( instanceId )
280280 if ( osName === 'Amazon Linux' ) {
281281 return 'ec2-user'
282282 }
0 commit comments