3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
import * 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'
8
7
import { Ec2Selection } from './prompter'
9
8
import { getOrInstallCli } from '../../shared/utilities/cliUtils'
10
9
import { isCloud9 } from '../../shared/extensionUtilities'
11
10
import { ToolkitError } from '../../shared/errors'
12
- import { SsmClient } from '../../shared/clients/ssmClient '
11
+ import { SsmClient } from '../../shared/clients/ssm '
13
12
import { Ec2Client } from '../../shared/clients/ec2Client'
14
13
import {
15
14
VscodeRemoteConnection ,
@@ -35,13 +34,14 @@ import { SshConfig } from '../../shared/sshConfig'
35
34
import { SshKeyPair } from './sshKeyPair'
36
35
import { Ec2SessionTracker } from './remoteSessionManager'
37
36
import { getEc2SsmEnv } from './utils'
37
+ import { Session , StartSessionResponse } from '@aws-sdk/client-ssm'
38
38
39
39
export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect' | 'EC2SSMAgentStatus'
40
40
41
41
export interface Ec2RemoteEnv extends VscodeRemoteConnection {
42
42
selection : Ec2Selection
43
43
keyPair : SshKeyPair
44
- ssmSession : SSM . StartSessionResponse
44
+ ssmSession : StartSessionResponse
45
45
}
46
46
47
47
export type Ec2OS = 'Amazon Linux' | 'Ubuntu' | 'macOS'
@@ -51,7 +51,7 @@ interface RemoteUser {
51
51
}
52
52
53
53
export class Ec2Connecter implements vscode . Disposable {
54
- protected ssmClient : SsmClient
54
+ protected ssm : SsmClient
55
55
protected ec2Client : Ec2Client
56
56
protected iamClient : DefaultIamClient
57
57
protected sessionManager : Ec2SessionTracker
@@ -65,10 +65,10 @@ export class Ec2Connecter implements vscode.Disposable {
65
65
)
66
66
67
67
public constructor ( readonly regionCode : string ) {
68
- this . ssmClient = this . createSsmSdkClient ( )
68
+ this . ssm = this . createSsmSdkClient ( )
69
69
this . ec2Client = this . createEc2SdkClient ( )
70
70
this . iamClient = this . createIamSdkClient ( )
71
- this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssmClient )
71
+ this . sessionManager = new Ec2SessionTracker ( regionCode , this . ssm )
72
72
}
73
73
74
74
protected createSsmSdkClient ( ) : SsmClient {
@@ -83,7 +83,7 @@ export class Ec2Connecter implements vscode.Disposable {
83
83
return new DefaultIamClient ( this . regionCode )
84
84
}
85
85
86
- public async addActiveSession ( sessionId : SSM . SessionId , instanceId : EC2 . InstanceId ) : Promise < void > {
86
+ public async addActiveSession ( sessionId : string , instanceId : EC2 . InstanceId ) : Promise < void > {
87
87
await this . sessionManager . addSession ( instanceId , sessionId )
88
88
}
89
89
@@ -151,7 +151,7 @@ export class Ec2Connecter implements vscode.Disposable {
151
151
}
152
152
153
153
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'
155
155
156
156
if ( ! isSsmAgentRunning ) {
157
157
this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
@@ -178,15 +178,15 @@ export class Ec2Connecter implements vscode.Disposable {
178
178
shellArgs : shellArgs ,
179
179
}
180
180
181
- await openRemoteTerminal ( terminalOptions , ( ) => this . ssmClient . terminateSession ( session ) ) . catch ( ( err ) => {
181
+ await openRemoteTerminal ( terminalOptions , ( ) => this . ssm . terminateSession ( session ) ) . catch ( ( err ) => {
182
182
throw ToolkitError . chain ( err , 'Failed to open ec2 instance.' )
183
183
} )
184
184
}
185
185
186
186
public async attemptToOpenEc2Terminal ( selection : Ec2Selection ) : Promise < void > {
187
187
await this . checkForStartSessionError ( selection )
188
188
try {
189
- const response = await this . ssmClient . startSession ( selection . instanceId )
189
+ const response = await this . ssm . startSession ( selection . instanceId )
190
190
await this . openSessionInTerminal ( response , selection )
191
191
} catch ( err : unknown ) {
192
192
this . throwConnectionError ( '' , selection , err as Error )
@@ -198,7 +198,7 @@ export class Ec2Connecter implements vscode.Disposable {
198
198
199
199
const remoteUser = await this . getRemoteUser ( selection . instanceId )
200
200
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' )
202
202
try {
203
203
await testSshConnection (
204
204
remoteEnv . SessionProcess ,
@@ -218,7 +218,7 @@ export class Ec2Connecter implements vscode.Disposable {
218
218
const message = err instanceof SshError ? 'Testing SSH connection to instance failed' : ''
219
219
this . throwConnectionError ( message , selection , err as Error )
220
220
} finally {
221
- await this . ssmClient . terminateSession ( testSession )
221
+ await this . ssm . terminateSession ( testSession )
222
222
}
223
223
}
224
224
@@ -232,8 +232,8 @@ export class Ec2Connecter implements vscode.Disposable {
232
232
return remoteEnv
233
233
}
234
234
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' )
237
237
await this . addActiveSession ( instanceId , ssmSession . SessionId ! )
238
238
return ssmSession
239
239
}
@@ -308,7 +308,7 @@ export class Ec2Connecter implements vscode.Disposable {
308
308
}
309
309
310
310
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' , {
312
312
commands : [ command ] ,
313
313
} )
314
314
}
@@ -331,7 +331,7 @@ export class Ec2Connecter implements vscode.Disposable {
331
331
}
332
332
333
333
public async getRemoteUser ( instanceId : string ) : Promise < RemoteUser > {
334
- const os = await this . ssmClient . getTargetPlatformName ( instanceId )
334
+ const os = await this . ssm . getTargetPlatformName ( instanceId )
335
335
if ( os === 'Amazon Linux' ) {
336
336
return { name : 'ec2-user' , os }
337
337
}
0 commit comments