Skip to content

Commit 086ba97

Browse files
authored
refactor(ssm): migrate to aws-sdk v3 (aws#8067)
## Problem AWS SDK V2 is at EOL. ## Solution Migrate SSM client to V3 --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 19e8e1c commit 086ba97

File tree

17 files changed

+132
-99
lines changed

17 files changed

+132
-99
lines changed

packages/core/src/awsService/ec2/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Ec2Instance } from '../../shared/clients/ec2'
77
import { copyToClipboard } from '../../shared/utilities/messages'
88
import { Ec2Selection } from './prompter'
99
import { sshLogFileLocation } from '../../shared/sshConfig'
10-
import { SSM } from 'aws-sdk'
10+
import { StartSessionResponse } from '@aws-sdk/client-ssm'
1111
import { getLogger } from '../../shared/logger/logger'
1212

1313
export function getIconCode(instance: Ec2Instance) {
@@ -33,7 +33,7 @@ export async function copyInstanceId(instanceId: string): Promise<void> {
3333
export function getEc2SsmEnv(
3434
selection: Ec2Selection,
3535
ssmPath: string,
36-
session: SSM.StartSessionResponse
36+
session: StartSessionResponse
3737
): NodeJS.ProcessEnv {
3838
return Object.assign(
3939
{

packages/core/src/awsService/ecs/util.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { isCloud9 } from '../../shared/extensionUtilities'
1515
import { getOrInstallCli } from '../../shared/utilities/cliUtils'
1616
import { Session, TaskDefinition } from 'aws-sdk/clients/ecs'
1717
import { getLogger } from '../../shared/logger/logger'
18-
import { SSM } from 'aws-sdk'
18+
import { SSMClient, TerminateSessionCommand } from '@aws-sdk/client-ssm'
1919
import { fromExtensionManifest } from '../../shared/settings'
2020
import { ecsTaskPermissionsUrl } from '../../shared/constants'
2121

@@ -93,12 +93,13 @@ export async function prepareCommand(
9393

9494
async function terminateSession() {
9595
const sessionId = session.sessionId!
96-
const ssm = await globals.sdkClientBuilder.createAwsService(SSM, undefined, client.regionCode)
97-
ssm.terminateSession({ SessionId: sessionId })
98-
.promise()
99-
.catch((err) => {
100-
getLogger().warn(`ecs: failed to terminate session "${sessionId}": %s`, err)
101-
})
96+
const ssm = globals.sdkClientBuilderV3.createAwsService({
97+
serviceClient: SSMClient,
98+
clientOptions: { region: client.regionCode },
99+
})
100+
ssm.send(new TerminateSessionCommand({ SessionId: sessionId })).catch((err) => {
101+
getLogger().warn(`ecs: failed to terminate session "${sessionId}": %s`, err)
102+
})
102103
}
103104

104105
return { path: ssmPlugin, args, dispose: () => void terminateSession() }

packages/core/src/shared/clients/ssmDocumentClient.ts

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { SSM } from 'aws-sdk'
6+
import {
7+
CreateDocumentCommand,
8+
CreateDocumentRequest,
9+
CreateDocumentResult,
10+
DeleteDocumentCommand,
11+
DeleteDocumentRequest,
12+
DeleteDocumentResult,
13+
DescribeDocumentCommand,
14+
DescribeDocumentRequest,
15+
DescribeDocumentResult,
16+
DocumentFormat,
17+
DocumentIdentifier,
18+
DocumentVersionInfo,
19+
GetDocumentCommand,
20+
GetDocumentRequest,
21+
GetDocumentResult,
22+
ListDocumentsCommand,
23+
ListDocumentsRequest,
24+
ListDocumentsResult,
25+
ListDocumentVersionsCommand,
26+
ListDocumentVersionsRequest,
27+
ListDocumentVersionsResult,
28+
SSMClient,
29+
UpdateDocumentCommand,
30+
UpdateDocumentDefaultVersionCommand,
31+
UpdateDocumentDefaultVersionRequest,
32+
UpdateDocumentDefaultVersionResult,
33+
UpdateDocumentRequest,
34+
UpdateDocumentResult,
35+
} from '@aws-sdk/client-ssm'
736
import globals from '../extensionGlobals'
837

938
import { ClassToInterfaceType } from '../utilities/tsUtils'
@@ -12,23 +41,21 @@ export type SsmDocumentClient = ClassToInterfaceType<DefaultSsmDocumentClient>
1241
export class DefaultSsmDocumentClient {
1342
public constructor(public readonly regionCode: string) {}
1443

15-
public async deleteDocument(documentName: string): Promise<SSM.Types.DeleteDocumentResult> {
16-
const client = await this.createSdkClient()
44+
public async deleteDocument(documentName: string): Promise<DeleteDocumentResult> {
45+
const client = this.createSdkClient()
1746

18-
const request: SSM.Types.DeleteDocumentRequest = {
47+
const request: DeleteDocumentRequest = {
1948
Name: documentName,
2049
}
2150

22-
return await client.deleteDocument(request).promise()
51+
return await client.send(new DeleteDocumentCommand(request))
2352
}
2453

25-
public async *listDocuments(
26-
request: SSM.Types.ListDocumentsRequest = {}
27-
): AsyncIterableIterator<SSM.DocumentIdentifier> {
28-
const client = await this.createSdkClient()
54+
public async *listDocuments(request: ListDocumentsRequest = {}): AsyncIterableIterator<DocumentIdentifier> {
55+
const client = this.createSdkClient()
2956

3057
do {
31-
const response: SSM.Types.ListDocumentsResult = await client.listDocuments(request).promise()
58+
const response: ListDocumentsResult = await client.send(new ListDocumentsCommand(request))
3259

3360
if (response.DocumentIdentifiers) {
3461
yield* response.DocumentIdentifiers
@@ -38,15 +65,15 @@ export class DefaultSsmDocumentClient {
3865
} while (request.NextToken)
3966
}
4067

41-
public async *listDocumentVersions(documentName: string): AsyncIterableIterator<SSM.Types.DocumentVersionInfo> {
42-
const client = await this.createSdkClient()
68+
public async *listDocumentVersions(documentName: string): AsyncIterableIterator<DocumentVersionInfo> {
69+
const client = this.createSdkClient()
4370

44-
const request: SSM.Types.ListDocumentVersionsRequest = {
71+
const request: ListDocumentVersionsRequest = {
4572
Name: documentName,
4673
}
4774

4875
do {
49-
const response: SSM.Types.ListDocumentVersionsResult = await client.listDocumentVersions(request).promise()
76+
const response: ListDocumentVersionsResult = await client.send(new ListDocumentVersionsCommand(request))
5077

5178
if (response.DocumentVersions) {
5279
yield* response.DocumentVersions
@@ -56,60 +83,63 @@ export class DefaultSsmDocumentClient {
5683
} while (request.NextToken)
5784
}
5885

59-
public async describeDocument(documentName: string, documentVersion?: string): Promise<SSM.DescribeDocumentResult> {
60-
const client = await this.createSdkClient()
86+
public async describeDocument(documentName: string, documentVersion?: string): Promise<DescribeDocumentResult> {
87+
const client = this.createSdkClient()
6188

62-
const request: SSM.Types.DescribeDocumentRequest = {
89+
const request: DescribeDocumentRequest = {
6390
Name: documentName,
6491
DocumentVersion: documentVersion,
6592
}
6693

67-
return await client.describeDocument(request).promise()
94+
return await client.send(new DescribeDocumentCommand(request))
6895
}
6996

7097
public async getDocument(
7198
documentName: string,
7299
documentVersion?: string,
73-
documentFormat?: string
74-
): Promise<SSM.Types.GetDocumentResult> {
75-
const client = await this.createSdkClient()
100+
documentFormat?: DocumentFormat
101+
): Promise<GetDocumentResult> {
102+
const client = this.createSdkClient()
76103

77-
const request: SSM.Types.GetDocumentRequest = {
104+
const request: GetDocumentRequest = {
78105
Name: documentName,
79106
DocumentVersion: documentVersion,
80107
DocumentFormat: documentFormat,
81108
}
82109

83-
return await client.getDocument(request).promise()
110+
return await client.send(new GetDocumentCommand(request))
84111
}
85112

86-
public async createDocument(request: SSM.Types.CreateDocumentRequest): Promise<SSM.Types.CreateDocumentResult> {
87-
const client = await this.createSdkClient()
113+
public async createDocument(request: CreateDocumentRequest): Promise<CreateDocumentResult> {
114+
const client = this.createSdkClient()
88115

89-
return await client.createDocument(request).promise()
116+
return await client.send(new CreateDocumentCommand(request))
90117
}
91118

92-
public async updateDocument(request: SSM.Types.UpdateDocumentRequest): Promise<SSM.Types.UpdateDocumentResult> {
93-
const client = await this.createSdkClient()
119+
public async updateDocument(request: UpdateDocumentRequest): Promise<UpdateDocumentResult> {
120+
const client = this.createSdkClient()
94121

95-
return await client.updateDocument(request).promise()
122+
return await client.send(new UpdateDocumentCommand(request))
96123
}
97124

98125
public async updateDocumentVersion(
99126
documentName: string,
100127
documentVersion: string
101-
): Promise<SSM.Types.UpdateDocumentDefaultVersionResult> {
102-
const client = await this.createSdkClient()
128+
): Promise<UpdateDocumentDefaultVersionResult> {
129+
const client = this.createSdkClient()
103130

104-
const request: SSM.Types.UpdateDocumentDefaultVersionRequest = {
131+
const request: UpdateDocumentDefaultVersionRequest = {
105132
Name: documentName,
106133
DocumentVersion: documentVersion,
107134
}
108135

109-
return await client.updateDocumentDefaultVersion(request).promise()
136+
return await client.send(new UpdateDocumentDefaultVersionCommand(request))
110137
}
111138

112-
private async createSdkClient(): Promise<SSM> {
113-
return await globals.sdkClientBuilder.createAwsService(SSM, undefined, this.regionCode)
139+
private createSdkClient(): SSMClient {
140+
return globals.sdkClientBuilderV3.createAwsService({
141+
serviceClient: SSMClient,
142+
clientOptions: { region: this.regionCode },
143+
})
114144
}
115145
}

packages/core/src/shared/extensions/ssh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ChildProcess, ChildProcessResult } from '../utilities/processUtils'
1212
import { ArrayConstructor, NonNullObject } from '../utilities/typeConstructors'
1313
import { Settings } from '../settings'
1414
import { VSCODE_EXTENSION_ID } from '../extensions'
15-
import { SSM } from 'aws-sdk'
15+
import { StartSessionResponse } from '@aws-sdk/client-ssm'
1616
import { ErrorInformation, ToolkitError } from '../errors'
1717

1818
const localize = nls.loadMessageBundle()
@@ -144,7 +144,7 @@ export async function testSshConnection(
144144
hostname: string,
145145
sshPath: string,
146146
user: string,
147-
session: SSM.StartSessionResponse
147+
session: StartSessionResponse
148148
): Promise<ChildProcessResult | never> {
149149
const env = { SESSION_ID: session.SessionId, STREAM_URL: session.StreamUrl, TOKEN: session.TokenValue }
150150
const process = new ProcessClass(sshPath, ['-T', `${user}@${hostname}`, 'echo "test connection succeeded" && exit'])

packages/core/src/ssmDocument/commands/openDocumentItem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vscode-nls'
77
const localize = nls.loadMessageBundle()
88

9-
import { SSM } from 'aws-sdk'
9+
import { DocumentFormat, DocumentVersionInfo } from '@aws-sdk/client-ssm'
1010
import * as vscode from 'vscode'
1111
import { DocumentItemNode } from '../explorer/documentItemNode'
1212
import { AwsContext } from '../../shared/awsContext'
@@ -16,7 +16,7 @@ import { showViewLogsMessage } from '../../shared/utilities/messages'
1616
import { telemetry } from '../../shared/telemetry/telemetry'
1717
import { Result } from '../../shared/telemetry/telemetry'
1818

19-
export async function openDocumentItem(node: DocumentItemNode, awsContext: AwsContext, format?: string) {
19+
export async function openDocumentItem(node: DocumentItemNode, awsContext: AwsContext, format?: DocumentFormat) {
2020
const logger: Logger = getLogger()
2121

2222
let result: Result = 'Succeeded'
@@ -65,7 +65,7 @@ export async function openDocumentItemYaml(node: DocumentItemNode, awsContext: A
6565
await openDocumentItem(node, awsContext, 'YAML')
6666
}
6767

68-
async function promptUserforDocumentVersion(versions: SSM.Types.DocumentVersionInfo[]): Promise<string | undefined> {
68+
async function promptUserforDocumentVersion(versions: DocumentVersionInfo[]): Promise<string | undefined> {
6969
// Prompt user to pick document version
7070
const quickPickItems: vscode.QuickPickItem[] = []
7171
for (const version of versions) {

packages/core/src/ssmDocument/commands/publishDocument.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { SSM } from 'aws-sdk'
6+
import { CreateDocumentRequest, UpdateDocumentRequest } from '@aws-sdk/client-ssm'
77
import * as vscode from 'vscode'
88
import * as nls from 'vscode-nls'
99
const localize = nls.loadMessageBundle()
@@ -75,7 +75,7 @@ export async function createDocument(
7575
logger.info(`Creating Systems Manager Document '${wizardResponse.name}'`)
7676

7777
try {
78-
const request: SSM.CreateDocumentRequest = {
78+
const request: CreateDocumentRequest = {
7979
Content: textDocument.getText(),
8080
Name: wizardResponse.name,
8181
DocumentType: wizardResponse.documentType,
@@ -109,7 +109,7 @@ export async function updateDocument(
109109
logger.info(`Updating Systems Manager Document '${wizardResponse.name}'`)
110110

111111
try {
112-
const request: SSM.UpdateDocumentRequest = {
112+
const request: UpdateDocumentRequest = {
113113
Content: textDocument.getText(),
114114
Name: wizardResponse.name,
115115
DocumentVersion: '$LATEST',

packages/core/src/ssmDocument/commands/updateDocumentVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vscode-nls'
77
const localize = nls.loadMessageBundle()
88

9-
import { SSM } from 'aws-sdk'
9+
import { DocumentVersionInfo } from '@aws-sdk/client-ssm'
1010
import * as vscode from 'vscode'
1111
import { AwsContext } from '../../shared/awsContext'
1212
import { getLogger, Logger } from '../../shared/logger/logger'
@@ -76,7 +76,7 @@ export async function updateDocumentVersion(node: DocumentItemNodeWriteable, aws
7676
}
7777
}
7878

79-
async function promptUserforDocumentVersion(versions: SSM.Types.DocumentVersionInfo[]): Promise<string | undefined> {
79+
async function promptUserforDocumentVersion(versions: DocumentVersionInfo[]): Promise<string | undefined> {
8080
// Prompt user to pick document version
8181
const quickPickItems: vscode.QuickPickItem[] = []
8282
for (const version of versions) {

packages/core/src/ssmDocument/explorer/documentItemNode.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { SSM } from 'aws-sdk'
7-
6+
import { DocumentFormat, DocumentIdentifier, DocumentVersionInfo, GetDocumentResult } from '@aws-sdk/client-ssm'
87
import { SsmDocumentClient } from '../../shared/clients/ssmDocumentClient'
98
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
109

@@ -13,7 +12,7 @@ import { getIcon } from '../../shared/icons'
1312

1413
export class DocumentItemNode extends AWSTreeNodeBase {
1514
public constructor(
16-
private documentItem: SSM.Types.DocumentIdentifier,
15+
private documentItem: DocumentIdentifier,
1716
public readonly client: SsmDocumentClient,
1817
public override readonly regionCode: string
1918
) {
@@ -23,7 +22,7 @@ export class DocumentItemNode extends AWSTreeNodeBase {
2322
this.iconPath = getIcon('vscode-file')
2423
}
2524

26-
public update(documentItem: SSM.Types.DocumentIdentifier): void {
25+
public update(documentItem: DocumentIdentifier): void {
2726
this.documentItem = documentItem
2827
this.label = this.documentName
2928
}
@@ -38,13 +37,13 @@ export class DocumentItemNode extends AWSTreeNodeBase {
3837

3938
public async getDocumentContent(
4039
documentVersion?: string,
41-
documentFormat?: string
42-
): Promise<SSM.Types.GetDocumentResult> {
40+
documentFormat?: DocumentFormat
41+
): Promise<GetDocumentResult> {
4342
if (!this.documentName || !this.documentName.length) {
4443
return Promise.resolve({})
4544
}
4645

47-
let resolvedDocumentFormat: string | undefined
46+
let resolvedDocumentFormat: DocumentFormat | undefined
4847

4948
if (documentFormat === undefined) {
5049
// retrieves the document format from the service
@@ -61,7 +60,7 @@ export class DocumentItemNode extends AWSTreeNodeBase {
6160
)
6261
}
6362

64-
public async listSchemaVersion(): Promise<SSM.Types.DocumentVersionInfo[]> {
63+
public async listSchemaVersion(): Promise<DocumentVersionInfo[]> {
6564
return await toArrayAsync(this.client.listDocumentVersions(this.documentName))
6665
}
6766
}

0 commit comments

Comments
 (0)