-
Notifications
You must be signed in to change notification settings - Fork 738
fix(ec2): remove SSM session state w/ best effort approaches. #5616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 225 commits
b7399c5
588594d
1c57e45
814ba96
b5d2c88
08ba106
3caba57
f2894ba
f0f5086
5be1f8d
3c096cd
13b2bc0
8fbbc8d
57dbde6
fb9f1e8
f94fe64
fdec798
545b8a7
4f8c680
222fcfd
0e5f7a2
e87f24d
3764b4a
1c3be08
93e23f0
d742eef
056e807
153bf62
bd71166
e027e40
9d62154
f28809b
3cc9aa6
732778f
2cbb723
26faa78
ea30d86
52a2fde
8fac525
004ac0b
f85f0ee
29d6b62
506be9a
2022004
8560da2
9022ec2
fd1703d
9e0c16e
1f53a3f
eb92609
cec3ede
024eb7b
38559be
b217377
19ad794
7794b67
adae37b
d3a4276
0772dd2
b4c03c3
b76e22f
98f03fb
6cc4cc5
d147b22
d72f9c9
bd709da
bffa367
8062ed6
f7999b1
f2a7786
cf05c8e
f0900d7
10566c1
2b749a3
bf25145
de97b43
1914fe8
ce7beb9
a5cf7f3
177aa07
dd82ff9
76eb0fd
5ad533f
6efd4fd
4a68497
ba21411
5ec5496
6c03515
7e6c56e
19d3e2c
886a41e
a4a4626
8b36799
72ae902
b08bbdb
c4348b4
02b2a2b
e373be8
0f2c01d
718c402
a21d6f8
60566f5
e15c0a2
41eade4
33fbd79
8cb386d
84fa815
dca607e
f6ac8e3
e15e184
6950712
d951675
2a63ae3
1087678
84ea20a
eed3a09
4b94c83
65ad6ac
febac95
ee149b7
d70c415
aa56c93
90b248b
950ca3c
f17580d
ac4e711
7441de1
ef427f2
a0cea9d
740baf8
c60d540
2a08bb7
24a25d0
27179ab
a8a92ae
d6896c1
e201693
3bbabd1
8a733e6
8a7e1ae
9ac421f
819203f
65133a4
de04def
9a55520
b0c1f02
59e9f9c
53a678b
0a26c22
fc4af9e
2f393c8
6eb3450
f9c5d91
f72acc7
19eb5d1
ca86046
57ad523
dd05a0d
40abd17
ae3851c
9cbcb48
4d6cd41
d4a2244
ac6d473
6cab577
a034dc3
2854015
f21201f
c9d6eff
49efa8b
0cc83e3
996362c
1e6cdcf
4e97666
9d9fa8d
79b8f81
681771e
955308c
341bff3
e2ac9c8
1a47575
65b2ff2
234a26d
8a16fa7
b1f05f5
57e887c
656a58c
61eb6bb
cf70ff6
b77dc8d
548f69e
f152943
1af46cd
dda254c
28798b6
0e9d0e8
cdf23cb
c3bfbf2
1e7f0e8
987c9cf
decca64
656ddaf
5cfa899
e37a46f
eab2f7d
a8051de
3efa868
05b107b
2e7c79f
45b62e2
d204f23
887bcf4
e8bca90
2ac7bfe
47b8425
3c3e01c
8db83d8
dc315c0
6a4a452
585d846
6e2b3e2
dc31929
084c1b4
4dd59ff
8aeb671
3d5e718
50f9a77
5af92dc
bcbb72d
f94f46d
ce29252
cf67383
97723b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,9 @@ import { SafeEc2Instance } from '../../../shared/clients/ec2Client' | |
| import globals from '../../../shared/extensionGlobals' | ||
| import { getIconCode } from '../utils' | ||
| import { Ec2Selection } from '../prompter' | ||
| import { Ec2ParentNode } from './ec2ParentNode' | ||
| import { Ec2Node, Ec2ParentNode } from './ec2ParentNode' | ||
| import { EC2 } from 'aws-sdk' | ||
| import { getLogger } from '../../../shared' | ||
|
|
||
| export const Ec2InstanceRunningContext = 'awsEc2RunningNode' | ||
| export const Ec2InstanceStoppedContext = 'awsEc2StoppedNode' | ||
|
|
@@ -100,3 +101,14 @@ export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode | |
| await vscode.commands.executeCommand('aws.refreshAwsExplorerNode', this) | ||
| } | ||
| } | ||
|
|
||
| export async function refreshExplorerNode(node?: Ec2Node) { | ||
|
||
| if (node) { | ||
| const n = node instanceof Ec2InstanceNode ? node.parent : node | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be generalized. I think possibly was, on the https://github.com/aws/aws-toolkit-vscode-staging/tree/feature/lambda-get-started branch. No action needed here, for now. |
||
| try { | ||
| await n.refreshNode() | ||
| } catch (e) { | ||
| getLogger().error('refreshNode failed: %s', (e as Error).message) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { EC2, SSM } from 'aws-sdk' | ||
| import { SsmClient } from '../../shared/clients/ssmClient' | ||
|
|
||
| export class Ec2RemoteSessionManager { | ||
| private activeSessions: Map<EC2.InstanceId, SSM.SessionId> | ||
|
|
||
| public constructor( | ||
| readonly regionCode: string, | ||
| protected ssmClient: SsmClient | ||
| ) { | ||
| this.activeSessions = new Map<EC2.InstanceId, SSM.SessionId>() | ||
| } | ||
|
|
||
| public async addSession(instanceId: EC2.InstanceId, sessionId: SSM.SessionId): Promise<void> { | ||
| if (this.isConnectedTo(instanceId)) { | ||
| const existingSessionId = this.activeSessions.get(instanceId)! | ||
| await this.ssmClient.terminateSessionFromId(existingSessionId) | ||
| this.activeSessions.set(instanceId, sessionId) | ||
| } else { | ||
| this.activeSessions.set(instanceId, sessionId) | ||
| } | ||
| } | ||
|
|
||
| private async disconnectEnv(instanceId: EC2.InstanceId): Promise<void> { | ||
| await this.ssmClient.terminateSessionFromId(this.activeSessions.get(instanceId)!) | ||
| this.activeSessions.delete(instanceId) | ||
| } | ||
|
|
||
| public async closeConnections(): Promise<void> { | ||
justinmk3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.activeSessions.forEach(async (_sessionId, instanceId) => await this.disconnectEnv(instanceId)) | ||
| } | ||
|
|
||
| public isConnectedTo(instanceId: EC2.InstanceId): boolean { | ||
| return this.activeSessions.has(instanceId) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,11 @@ | |
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { SSM } from 'aws-sdk' | ||
|
||
| import { SafeEc2Instance } from '../../shared/clients/ec2Client' | ||
| import { copyToClipboard } from '../../shared/utilities/messages' | ||
| import { Ec2Selection } from './prompter' | ||
| import { sshLogFileLocation } from '../../shared/sshConfig' | ||
|
|
||
| export function getIconCode(instance: SafeEc2Instance) { | ||
| if (instance.LastSeenStatus === 'running') { | ||
|
|
@@ -16,3 +20,25 @@ export function getIconCode(instance: SafeEc2Instance) { | |
|
|
||
| return 'loading~spin' | ||
| } | ||
|
|
||
| export async function copyInstanceId(instanceId: string): Promise<void> { | ||
| await copyToClipboard(instanceId, 'Id') | ||
| } | ||
|
|
||
| export function getEc2SsmEnv( | ||
| selection: Ec2Selection, | ||
| ssmPath: string, | ||
| session: SSM.StartSessionResponse | ||
| ): NodeJS.ProcessEnv { | ||
| return Object.assign( | ||
| { | ||
| AWS_REGION: selection.region, | ||
| AWS_SSM_CLI: ssmPath, | ||
| LOG_FILE_LOCATION: sshLogFileLocation('ec2', selection.instanceId), | ||
| STREAM_URL: session.StreamUrl, | ||
| SESSION_ID: session.SessionId, | ||
| TOKEN: session.TokenValue, | ||
| }, | ||
| process.env | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit subtle that this is actually adding to a global long-lived collection. This logic should live closer to that collection, possibly in a class or something.
Also need to log a warning if the number of connections exceeds a big number, until we have a better way to have visbility and validation of these long-lived collections (which can caused hidden bugs / perf issues).