Skip to content

Commit 247c267

Browse files
committed
refactor(iot): migrate to aws-sdk v3
1 parent 258022e commit 247c267

File tree

9 files changed

+861
-305
lines changed

9 files changed

+861
-305
lines changed

package-lock.json

Lines changed: 415 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,13 @@
533533
"@types/sinon": "^10.0.5",
534534
"@types/sinonjs__fake-timers": "^8.1.2",
535535
"@types/stream-buffers": "^3.0.7",
536+
"@types/svgdom": "^0.1.2",
536537
"@types/tcp-port-used": "^1.0.1",
537538
"@types/uuid": "^9.0.1",
538539
"@types/whatwg-url": "^11.0.4",
539540
"@types/xml2js": "^0.4.11",
540-
"@types/svgdom": "^0.1.2",
541541
"@vue/compiler-sfc": "^3.3.2",
542+
"aws-sdk-client-mock": "^4.1.0",
542543
"c8": "^9.0.0",
543544
"circular-dependency-plugin": "^5.2.2",
544545
"css-loader": "^6.10.0",
@@ -566,7 +567,6 @@
566567
"@amzn/amazon-q-developer-streaming-client": "file:../../src.gen/@amzn/amazon-q-developer-streaming-client",
567568
"@amzn/codewhisperer-streaming": "file:../../src.gen/@amzn/codewhisperer-streaming",
568569
"@amzn/sagemaker-client": "file:../../src.gen/@amzn/sagemaker-client/1.0.0.tgz",
569-
"@aws-sdk/credential-providers": "<3.731.0",
570570
"@aws-sdk/client-api-gateway": "<3.731.0",
571571
"@aws-sdk/client-apprunner": "<3.731.0",
572572
"@aws-sdk/client-cloudcontrol": "<3.731.0",
@@ -580,17 +580,20 @@
580580
"@aws-sdk/client-ec2": "<3.731.0",
581581
"@aws-sdk/client-glue": "^3.852.0",
582582
"@aws-sdk/client-iam": "<3.731.0",
583+
"@aws-sdk/client-iot": "~3.693.0",
584+
"@aws-sdk/client-iotsecuretunneling": "~3.693.0",
583585
"@aws-sdk/client-lambda": "<3.731.0",
584586
"@aws-sdk/client-s3": "<3.731.0",
585587
"@aws-sdk/client-s3-control": "^3.830.0",
586588
"@aws-sdk/client-sagemaker": "<3.696.0",
589+
"@aws-sdk/client-sfn": "<3.731.0",
587590
"@aws-sdk/client-ssm": "<3.731.0",
588591
"@aws-sdk/client-sso": "<3.731.0",
589592
"@aws-sdk/client-sso-oidc": "<3.731.0",
590-
"@aws-sdk/client-sfn": "<3.731.0",
591593
"@aws-sdk/credential-provider-env": "<3.731.0",
592594
"@aws-sdk/credential-provider-process": "<3.731.0",
593595
"@aws-sdk/credential-provider-sso": "<3.731.0",
596+
"@aws-sdk/credential-providers": "<3.731.0",
594597
"@aws-sdk/lib-storage": "<3.731.0",
595598
"@aws-sdk/property-provider": "<3.731.0",
596599
"@aws-sdk/protocol-http": "<3.731.0",
@@ -607,6 +610,7 @@
607610
"@smithy/service-error-classification": "^4.0.1",
608611
"@smithy/shared-ini-file-loader": "^4.0.0",
609612
"@smithy/util-retry": "^4.0.1",
613+
"@svgdotjs/svg.js": "^3.0.16",
610614
"@vscode/debugprotocol": "^1.57.0",
611615
"@zip.js/zip.js": "^2.7.41",
612616
"adm-zip": "^0.5.10",
@@ -625,6 +629,7 @@
625629
"http2": "^3.3.6",
626630
"i18n-ts": "^1.0.5",
627631
"immutable": "^4.3.0",
632+
"jaro-winkler": "^0.2.8",
628633
"jose": "5.4.1",
629634
"js-yaml": "^4.1.0",
630635
"jsonc-parser": "^3.2.0",
@@ -634,9 +639,11 @@
634639
"mime-types": "^2.1.32",
635640
"node-fetch": "^2.7.0",
636641
"portfinder": "^1.0.32",
642+
"protobufjs": "^7.2.6",
637643
"semver": "^7.5.4",
638644
"stream-buffers": "^3.0.2",
639645
"strip-ansi": "^5.2.0",
646+
"svgdom": "^0.1.0",
640647
"tcp-port-used": "^1.0.1",
641648
"vscode-languageclient": "^6.1.4",
642649
"vscode-languageserver": "^6.1.1",
@@ -649,11 +656,7 @@
649656
"winston-transport": "^4.6.0",
650657
"ws": "^8.16.0",
651658
"xml2js": "^0.6.1",
652-
"yaml-cfn": "^0.3.2",
653-
"protobufjs": "^7.2.6",
654-
"@svgdotjs/svg.js": "^3.0.16",
655-
"svgdom": "^0.1.0",
656-
"jaro-winkler": "^0.2.8"
659+
"yaml-cfn": "^0.3.2"
657660
},
658661
"overrides": {
659662
"webfont": {

packages/core/src/awsService/iot/commands/attachCertificate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createQuickPick, DataQuickPickItem } from '../../../shared/ui/pickerPro
1212
import { PromptResult } from '../../../shared/ui/prompter'
1313
import { IotClient } from '../../../shared/clients/iotClient'
1414
import { isValidResponse } from '../../../shared/wizards/wizard'
15-
import { Iot } from 'aws-sdk'
15+
import { Certificate, ListCertificatesResponse } from '@aws-sdk/client-iot'
1616

1717
export type CertGen = typeof getCertList
1818

@@ -53,8 +53,8 @@ export async function attachCertificateCommand(node: IotThingNode, promptFun = p
5353
/**
5454
* Prompts the user to pick a certificate to attach.
5555
*/
56-
async function promptForCert(iot: IotClient, certFetch: CertGen): Promise<PromptResult<Iot.Certificate>> {
57-
const placeHolder: DataQuickPickItem<Iot.Certificate> = {
56+
async function promptForCert(iot: IotClient, certFetch: CertGen): Promise<PromptResult<Certificate>> {
57+
const placeHolder: DataQuickPickItem<Certificate> = {
5858
label: 'No certificates found',
5959
data: undefined,
6060
}
@@ -71,10 +71,10 @@ async function promptForCert(iot: IotClient, certFetch: CertGen): Promise<Prompt
7171
*/
7272
async function* getCertList(iot: IotClient) {
7373
let marker: string | undefined = undefined
74-
let filteredCerts: Iot.Certificate[]
74+
let filteredCerts: Certificate[]
7575
do {
7676
try {
77-
const certResponse: Iot.ListCertificatesResponse = await iot.listCertificates({ marker })
77+
const certResponse: ListCertificatesResponse = await iot.listCertificates({ marker })
7878
marker = certResponse.nextMarker
7979

8080
/* These fields should always be defined when using the above API,

packages/core/src/lambda/remoteDebugging/ldkClient.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { IoTSecureTunneling, Lambda } from 'aws-sdk'
7+
import { Lambda } from 'aws-sdk'
8+
import {
9+
CloseTunnelCommand,
10+
IoTSecureTunnelingClient,
11+
ListTunnelsCommand,
12+
OpenTunnelCommand,
13+
RotateTunnelAccessTokenCommand,
14+
} from '@aws-sdk/client-iotsecuretunneling'
815
import { getClientId } from '../../shared/telemetry/util'
916
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
1017
import { LocalProxy } from './localProxy'
@@ -61,7 +68,7 @@ export class LdkClient {
6168
private localProxy: LocalProxy | undefined
6269
private static instanceCreating = false
6370
private lambdaClientCache: Map<string, DefaultLambdaClient> = new Map()
64-
private iotSTClientCache: Map<string, IoTSecureTunneling> = new Map()
71+
private iotSTClientCache: Map<string, IoTSecureTunnelingClient> = new Map()
6572

6673
constructor() {}
6774

@@ -97,9 +104,9 @@ export class LdkClient {
97104
return this.lambdaClientCache.get(region)!
98105
}
99106

100-
private async getIoTSTClient(region: string): Promise<IoTSecureTunneling> {
107+
private getIoTSTClient(region: string): IoTSecureTunnelingClient {
101108
if (!this.iotSTClientCache.has(region)) {
102-
this.iotSTClientCache.set(region, await getIoTSTClientWithAgent(region))
109+
this.iotSTClientCache.set(region, getIoTSTClientWithAgent(region))
103110
}
104111
return this.iotSTClientCache.get(region)!
105112
}
@@ -124,13 +131,13 @@ export class LdkClient {
124131
const vscodeUuid = getClientId(globals.globalState)
125132

126133
// Create IoTSecureTunneling client
127-
const iotSecureTunneling = await this.getIoTSTClient(region)
134+
const iotSecureTunneling = this.getIoTSTClient(region)
128135

129136
// Define tunnel identifier
130137
const tunnelIdentifier = `RemoteDebugging+${vscodeUuid}`
131138
const timeoutInMinutes = 720
132139
// List existing tunnels
133-
const listTunnelsResponse = await iotSecureTunneling.listTunnels({}).promise()
140+
const listTunnelsResponse = await iotSecureTunneling.send(new ListTunnelsCommand({}))
134141

135142
// Find tunnel with our identifier
136143
const existingTunnel = listTunnelsResponse.tunnelSummaries?.find(
@@ -150,20 +157,20 @@ export class LdkClient {
150157
return rotateResponse
151158
} else {
152159
// Close tunnel if less than 15 minutes remaining
153-
await iotSecureTunneling
154-
.closeTunnel({
160+
await iotSecureTunneling.send(
161+
new CloseTunnelCommand({
155162
tunnelId: existingTunnel.tunnelId,
156163
delete: false,
157164
})
158-
.promise()
165+
)
159166

160167
getLogger().info(`Closed tunnel ${existingTunnel.tunnelId} with less than 15 minutes remaining`)
161168
}
162169
}
163170

164171
// Create new tunnel
165-
const openTunnelResponse = await iotSecureTunneling
166-
.openTunnel({
172+
const openTunnelResponse = await iotSecureTunneling.send(
173+
new OpenTunnelCommand({
167174
description: tunnelIdentifier,
168175
timeoutConfig: {
169176
maxLifetimeTimeoutMinutes: timeoutInMinutes, // 12 hours
@@ -172,7 +179,7 @@ export class LdkClient {
172179
services: ['WSS'],
173180
},
174181
})
175-
.promise()
182+
)
176183

177184
getLogger().info(`Created new tunnel with ID: ${openTunnelResponse.tunnelId}`)
178185

@@ -189,13 +196,13 @@ export class LdkClient {
189196
// Refresh tunnel tokens
190197
async refreshTunnelTokens(tunnelId: string, region: string): Promise<TunnelInfo | undefined> {
191198
try {
192-
const iotSecureTunneling = await this.getIoTSTClient(region)
193-
const rotateResponse = await iotSecureTunneling
194-
.rotateTunnelAccessToken({
199+
const iotSecureTunneling = this.getIoTSTClient(region)
200+
const rotateResponse = await iotSecureTunneling.send(
201+
new RotateTunnelAccessTokenCommand({
195202
tunnelId: tunnelId,
196203
clientMode: 'ALL',
197204
})
198-
.promise()
205+
)
199206

200207
return {
201208
tunnelID: tunnelId,

packages/core/src/lambda/remoteDebugging/utils.ts

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

6-
import IoTSecureTunneling from 'aws-sdk/clients/iotsecuretunneling'
6+
import { IoTSecureTunnelingClient } from '@aws-sdk/client-iotsecuretunneling'
77
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
88
import { getUserAgent } from '../../shared/telemetry/util'
99
import globals from '../../shared/extensionGlobals'
@@ -29,13 +29,14 @@ export function getLambdaUserAgent(): string {
2929
return `${getUserAgent({ includePlatform: true, includeClientId: true })}`
3030
}
3131

32-
export function getIoTSTClientWithAgent(region: string): Promise<IoTSecureTunneling> {
32+
export function getIoTSTClientWithAgent(region: string): IoTSecureTunnelingClient {
3333
const customUserAgent = `${customUserAgentBase} ${getUserAgent({ includePlatform: true, includeClientId: true })}`
34-
return globals.sdkClientBuilder.createAwsService(
35-
IoTSecureTunneling,
36-
{
37-
customUserAgent,
34+
return globals.sdkClientBuilderV3.createAwsService({
35+
serviceClient: IoTSecureTunnelingClient,
36+
clientOptions: {
37+
userAgent: [[customUserAgent]],
38+
region,
3839
},
39-
region
40-
)
40+
userAgent: false,
41+
})
4142
}

0 commit comments

Comments
 (0)