Skip to content
Merged
4 changes: 2 additions & 2 deletions packages/core/src/awsService/ec2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Ec2Instance } from '../../shared/clients/ec2'
import { copyToClipboard } from '../../shared/utilities/messages'
import { Ec2Selection } from './prompter'
import { sshLogFileLocation } from '../../shared/sshConfig'
import { SSM } from 'aws-sdk'
import { StartSessionResponse } from '@aws-sdk/client-ssm'
import { getLogger } from '../../shared/logger/logger'

export function getIconCode(instance: Ec2Instance) {
Expand All @@ -33,7 +33,7 @@ export async function copyInstanceId(instanceId: string): Promise<void> {
export function getEc2SsmEnv(
selection: Ec2Selection,
ssmPath: string,
session: SSM.StartSessionResponse
session: StartSessionResponse
): NodeJS.ProcessEnv {
return Object.assign(
{
Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/awsService/ecs/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { isCloud9 } from '../../shared/extensionUtilities'
import { getOrInstallCli } from '../../shared/utilities/cliUtils'
import { Session, TaskDefinition } from 'aws-sdk/clients/ecs'
import { getLogger } from '../../shared/logger/logger'
import { SSM } from 'aws-sdk'
import { SSMClient, TerminateSessionCommand } from '@aws-sdk/client-ssm'
import { fromExtensionManifest } from '../../shared/settings'
import { ecsTaskPermissionsUrl } from '../../shared/constants'

Expand Down Expand Up @@ -93,12 +93,13 @@ export async function prepareCommand(

async function terminateSession() {
const sessionId = session.sessionId!
const ssm = await globals.sdkClientBuilder.createAwsService(SSM, undefined, client.regionCode)
ssm.terminateSession({ SessionId: sessionId })
.promise()
.catch((err) => {
getLogger().warn(`ecs: failed to terminate session "${sessionId}": %s`, err)
})
const ssm = globals.sdkClientBuilderV3.createAwsService({
serviceClient: SSMClient,
clientOptions: { region: client.regionCode },
})
ssm.send(new TerminateSessionCommand({ SessionId: sessionId })).catch((err) => {
getLogger().warn(`ecs: failed to terminate session "${sessionId}": %s`, err)
})
}

return { path: ssmPlugin, args, dispose: () => void terminateSession() }
Expand Down
100 changes: 65 additions & 35 deletions packages/core/src/shared/clients/ssmDocumentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,36 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SSM } from 'aws-sdk'
import {
CreateDocumentCommand,
CreateDocumentRequest,
CreateDocumentResult,
DeleteDocumentCommand,
DeleteDocumentRequest,
DeleteDocumentResult,
DescribeDocumentCommand,
DescribeDocumentRequest,
DescribeDocumentResult,
DocumentFormat,
DocumentIdentifier,
DocumentVersionInfo,
GetDocumentCommand,
GetDocumentRequest,
GetDocumentResult,
ListDocumentsCommand,
ListDocumentsRequest,
ListDocumentsResult,
ListDocumentVersionsCommand,
ListDocumentVersionsRequest,
ListDocumentVersionsResult,
SSMClient,
UpdateDocumentCommand,
UpdateDocumentDefaultVersionCommand,
UpdateDocumentDefaultVersionRequest,
UpdateDocumentDefaultVersionResult,
UpdateDocumentRequest,
UpdateDocumentResult,
} from '@aws-sdk/client-ssm'
import globals from '../extensionGlobals'

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

public async deleteDocument(documentName: string): Promise<SSM.Types.DeleteDocumentResult> {
const client = await this.createSdkClient()
public async deleteDocument(documentName: string): Promise<DeleteDocumentResult> {
const client = this.createSdkClient()

const request: SSM.Types.DeleteDocumentRequest = {
const request: DeleteDocumentRequest = {
Name: documentName,
}

return await client.deleteDocument(request).promise()
return await client.send(new DeleteDocumentCommand(request))
}

public async *listDocuments(
request: SSM.Types.ListDocumentsRequest = {}
): AsyncIterableIterator<SSM.DocumentIdentifier> {
const client = await this.createSdkClient()
public async *listDocuments(request: ListDocumentsRequest = {}): AsyncIterableIterator<DocumentIdentifier> {
const client = this.createSdkClient()

do {
const response: SSM.Types.ListDocumentsResult = await client.listDocuments(request).promise()
const response: ListDocumentsResult = await client.send(new ListDocumentsCommand(request))

if (response.DocumentIdentifiers) {
yield* response.DocumentIdentifiers
Expand All @@ -38,15 +65,15 @@ export class DefaultSsmDocumentClient {
} while (request.NextToken)
}

public async *listDocumentVersions(documentName: string): AsyncIterableIterator<SSM.Types.DocumentVersionInfo> {
const client = await this.createSdkClient()
public async *listDocumentVersions(documentName: string): AsyncIterableIterator<DocumentVersionInfo> {
const client = this.createSdkClient()

const request: SSM.Types.ListDocumentVersionsRequest = {
const request: ListDocumentVersionsRequest = {
Name: documentName,
}

do {
const response: SSM.Types.ListDocumentVersionsResult = await client.listDocumentVersions(request).promise()
const response: ListDocumentVersionsResult = await client.send(new ListDocumentVersionsCommand(request))

if (response.DocumentVersions) {
yield* response.DocumentVersions
Expand All @@ -56,60 +83,63 @@ export class DefaultSsmDocumentClient {
} while (request.NextToken)
}

public async describeDocument(documentName: string, documentVersion?: string): Promise<SSM.DescribeDocumentResult> {
const client = await this.createSdkClient()
public async describeDocument(documentName: string, documentVersion?: string): Promise<DescribeDocumentResult> {
const client = this.createSdkClient()

const request: SSM.Types.DescribeDocumentRequest = {
const request: DescribeDocumentRequest = {
Name: documentName,
DocumentVersion: documentVersion,
}

return await client.describeDocument(request).promise()
return await client.send(new DescribeDocumentCommand(request))
}

public async getDocument(
documentName: string,
documentVersion?: string,
documentFormat?: string
): Promise<SSM.Types.GetDocumentResult> {
const client = await this.createSdkClient()
documentFormat?: DocumentFormat
): Promise<GetDocumentResult> {
const client = this.createSdkClient()

const request: SSM.Types.GetDocumentRequest = {
const request: GetDocumentRequest = {
Name: documentName,
DocumentVersion: documentVersion,
DocumentFormat: documentFormat,
}

return await client.getDocument(request).promise()
return await client.send(new GetDocumentCommand(request))
}

public async createDocument(request: SSM.Types.CreateDocumentRequest): Promise<SSM.Types.CreateDocumentResult> {
const client = await this.createSdkClient()
public async createDocument(request: CreateDocumentRequest): Promise<CreateDocumentResult> {
const client = this.createSdkClient()

return await client.createDocument(request).promise()
return await client.send(new CreateDocumentCommand(request))
}

public async updateDocument(request: SSM.Types.UpdateDocumentRequest): Promise<SSM.Types.UpdateDocumentResult> {
const client = await this.createSdkClient()
public async updateDocument(request: UpdateDocumentRequest): Promise<UpdateDocumentResult> {
const client = this.createSdkClient()

return await client.updateDocument(request).promise()
return await client.send(new UpdateDocumentCommand(request))
}

public async updateDocumentVersion(
documentName: string,
documentVersion: string
): Promise<SSM.Types.UpdateDocumentDefaultVersionResult> {
const client = await this.createSdkClient()
): Promise<UpdateDocumentDefaultVersionResult> {
const client = this.createSdkClient()

const request: SSM.Types.UpdateDocumentDefaultVersionRequest = {
const request: UpdateDocumentDefaultVersionRequest = {
Name: documentName,
DocumentVersion: documentVersion,
}

return await client.updateDocumentDefaultVersion(request).promise()
return await client.send(new UpdateDocumentDefaultVersionCommand(request))
}

private async createSdkClient(): Promise<SSM> {
return await globals.sdkClientBuilder.createAwsService(SSM, undefined, this.regionCode)
private createSdkClient(): SSMClient {
return globals.sdkClientBuilderV3.createAwsService({
serviceClient: SSMClient,
clientOptions: { region: this.regionCode },
})
}
}
4 changes: 2 additions & 2 deletions packages/core/src/shared/extensions/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ChildProcess, ChildProcessResult } from '../utilities/processUtils'
import { ArrayConstructor, NonNullObject } from '../utilities/typeConstructors'
import { Settings } from '../settings'
import { VSCODE_EXTENSION_ID } from '../extensions'
import { SSM } from 'aws-sdk'
import { StartSessionResponse } from '@aws-sdk/client-ssm'
import { ErrorInformation, ToolkitError } from '../errors'

const localize = nls.loadMessageBundle()
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function testSshConnection(
hostname: string,
sshPath: string,
user: string,
session: SSM.StartSessionResponse
session: StartSessionResponse
): Promise<ChildProcessResult | never> {
const env = { SESSION_ID: session.SessionId, STREAM_URL: session.StreamUrl, TOKEN: session.TokenValue }
const process = new ProcessClass(sshPath, ['-T', `${user}@${hostname}`, 'echo "test connection succeeded" && exit'])
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/ssmDocument/commands/openDocumentItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import { SSM } from 'aws-sdk'
import { DocumentFormat, DocumentVersionInfo } from '@aws-sdk/client-ssm'
import * as vscode from 'vscode'
import { DocumentItemNode } from '../explorer/documentItemNode'
import { AwsContext } from '../../shared/awsContext'
Expand All @@ -16,7 +16,7 @@ import { showViewLogsMessage } from '../../shared/utilities/messages'
import { telemetry } from '../../shared/telemetry/telemetry'
import { Result } from '../../shared/telemetry/telemetry'

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

let result: Result = 'Succeeded'
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function openDocumentItemYaml(node: DocumentItemNode, awsContext: A
await openDocumentItem(node, awsContext, 'YAML')
}

async function promptUserforDocumentVersion(versions: SSM.Types.DocumentVersionInfo[]): Promise<string | undefined> {
async function promptUserforDocumentVersion(versions: DocumentVersionInfo[]): Promise<string | undefined> {
// Prompt user to pick document version
const quickPickItems: vscode.QuickPickItem[] = []
for (const version of versions) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/ssmDocument/commands/publishDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

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

try {
const request: SSM.CreateDocumentRequest = {
const request: CreateDocumentRequest = {
Content: textDocument.getText(),
Name: wizardResponse.name,
DocumentType: wizardResponse.documentType,
Expand Down Expand Up @@ -109,7 +109,7 @@ export async function updateDocument(
logger.info(`Updating Systems Manager Document '${wizardResponse.name}'`)

try {
const request: SSM.UpdateDocumentRequest = {
const request: UpdateDocumentRequest = {
Content: textDocument.getText(),
Name: wizardResponse.name,
DocumentVersion: '$LATEST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import { SSM } from 'aws-sdk'
import { DocumentVersionInfo } from '@aws-sdk/client-ssm'
import * as vscode from 'vscode'
import { AwsContext } from '../../shared/awsContext'
import { getLogger, Logger } from '../../shared/logger/logger'
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function updateDocumentVersion(node: DocumentItemNodeWriteable, aws
}
}

async function promptUserforDocumentVersion(versions: SSM.Types.DocumentVersionInfo[]): Promise<string | undefined> {
async function promptUserforDocumentVersion(versions: DocumentVersionInfo[]): Promise<string | undefined> {
// Prompt user to pick document version
const quickPickItems: vscode.QuickPickItem[] = []
for (const version of versions) {
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/ssmDocument/explorer/documentItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SSM } from 'aws-sdk'

import { DocumentFormat, DocumentIdentifier, DocumentVersionInfo, GetDocumentResult } from '@aws-sdk/client-ssm'
import { SsmDocumentClient } from '../../shared/clients/ssmDocumentClient'
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'

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

export class DocumentItemNode extends AWSTreeNodeBase {
public constructor(
private documentItem: SSM.Types.DocumentIdentifier,
private documentItem: DocumentIdentifier,
public readonly client: SsmDocumentClient,
public override readonly regionCode: string
) {
Expand All @@ -23,7 +22,7 @@ export class DocumentItemNode extends AWSTreeNodeBase {
this.iconPath = getIcon('vscode-file')
}

public update(documentItem: SSM.Types.DocumentIdentifier): void {
public update(documentItem: DocumentIdentifier): void {
this.documentItem = documentItem
this.label = this.documentName
}
Expand All @@ -38,13 +37,13 @@ export class DocumentItemNode extends AWSTreeNodeBase {

public async getDocumentContent(
documentVersion?: string,
documentFormat?: string
): Promise<SSM.Types.GetDocumentResult> {
documentFormat?: DocumentFormat
): Promise<GetDocumentResult> {
if (!this.documentName || !this.documentName.length) {
return Promise.resolve({})
}

let resolvedDocumentFormat: string | undefined
let resolvedDocumentFormat: DocumentFormat | undefined

if (documentFormat === undefined) {
// retrieves the document format from the service
Expand All @@ -61,7 +60,7 @@ export class DocumentItemNode extends AWSTreeNodeBase {
)
}

public async listSchemaVersion(): Promise<SSM.Types.DocumentVersionInfo[]> {
public async listSchemaVersion(): Promise<DocumentVersionInfo[]> {
return await toArrayAsync(this.client.listDocumentVersions(this.documentName))
}
}
Loading
Loading