4
4
*/
5
5
6
6
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'
8
15
import { getClientId } from '../../shared/telemetry/util'
9
16
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
10
17
import { LocalProxy } from './localProxy'
@@ -61,7 +68,7 @@ export class LdkClient {
61
68
private localProxy : LocalProxy | undefined
62
69
private static instanceCreating = false
63
70
private lambdaClientCache : Map < string , DefaultLambdaClient > = new Map ( )
64
- private iotSTClientCache : Map < string , IoTSecureTunneling > = new Map ( )
71
+ private iotSTClientCache : Map < string , IoTSecureTunnelingClient > = new Map ( )
65
72
66
73
constructor ( ) { }
67
74
@@ -97,9 +104,9 @@ export class LdkClient {
97
104
return this . lambdaClientCache . get ( region ) !
98
105
}
99
106
100
- private async getIoTSTClient ( region : string ) : Promise < IoTSecureTunneling > {
107
+ private getIoTSTClient ( region : string ) : IoTSecureTunnelingClient {
101
108
if ( ! this . iotSTClientCache . has ( region ) ) {
102
- this . iotSTClientCache . set ( region , await getIoTSTClientWithAgent ( region ) )
109
+ this . iotSTClientCache . set ( region , getIoTSTClientWithAgent ( region ) )
103
110
}
104
111
return this . iotSTClientCache . get ( region ) !
105
112
}
@@ -124,13 +131,13 @@ export class LdkClient {
124
131
const vscodeUuid = getClientId ( globals . globalState )
125
132
126
133
// Create IoTSecureTunneling client
127
- const iotSecureTunneling = await this . getIoTSTClient ( region )
134
+ const iotSecureTunneling = this . getIoTSTClient ( region )
128
135
129
136
// Define tunnel identifier
130
137
const tunnelIdentifier = `RemoteDebugging+${ vscodeUuid } `
131
138
const timeoutInMinutes = 720
132
139
// List existing tunnels
133
- const listTunnelsResponse = await iotSecureTunneling . listTunnels ( { } ) . promise ( )
140
+ const listTunnelsResponse = await iotSecureTunneling . send ( new ListTunnelsCommand ( { } ) )
134
141
135
142
// Find tunnel with our identifier
136
143
const existingTunnel = listTunnelsResponse . tunnelSummaries ?. find (
@@ -150,20 +157,20 @@ export class LdkClient {
150
157
return rotateResponse
151
158
} else {
152
159
// Close tunnel if less than 15 minutes remaining
153
- await iotSecureTunneling
154
- . closeTunnel ( {
160
+ await iotSecureTunneling . send (
161
+ new CloseTunnelCommand ( {
155
162
tunnelId : existingTunnel . tunnelId ,
156
163
delete : false ,
157
164
} )
158
- . promise ( )
165
+ )
159
166
160
167
getLogger ( ) . info ( `Closed tunnel ${ existingTunnel . tunnelId } with less than 15 minutes remaining` )
161
168
}
162
169
}
163
170
164
171
// Create new tunnel
165
- const openTunnelResponse = await iotSecureTunneling
166
- . openTunnel ( {
172
+ const openTunnelResponse = await iotSecureTunneling . send (
173
+ new OpenTunnelCommand ( {
167
174
description : tunnelIdentifier ,
168
175
timeoutConfig : {
169
176
maxLifetimeTimeoutMinutes : timeoutInMinutes , // 12 hours
@@ -172,7 +179,7 @@ export class LdkClient {
172
179
services : [ 'WSS' ] ,
173
180
} ,
174
181
} )
175
- . promise ( )
182
+ )
176
183
177
184
getLogger ( ) . info ( `Created new tunnel with ID: ${ openTunnelResponse . tunnelId } ` )
178
185
@@ -189,13 +196,13 @@ export class LdkClient {
189
196
// Refresh tunnel tokens
190
197
async refreshTunnelTokens ( tunnelId : string , region : string ) : Promise < TunnelInfo | undefined > {
191
198
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 ( {
195
202
tunnelId : tunnelId ,
196
203
clientMode : 'ALL' ,
197
204
} )
198
- . promise ( )
205
+ )
199
206
200
207
return {
201
208
tunnelID : tunnelId ,
0 commit comments