Skip to content

Commit 8b4bf74

Browse files
fix: Enhance LocalStack region detection and logging in IoT service connection
1 parent 0be6a4d commit 8b4bf74

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/extension/interceptor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ async function regularMode(context: any, event: any) {
4848
});
4949
}, 5 * 1000);
5050

51+
let region: string | undefined;
52+
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
53+
// it is localstack
54+
region = process.env.AWS_REGION;
55+
Logger.verbose(`Region is set to ${region} due to LocalStack detection`);
56+
}
57+
5158
const ioTService = await IoTService.connect({
5259
onMessage: async (message: IoTMessage) => {
5360
if (Logger.isVerbose()) {
@@ -83,6 +90,7 @@ async function regularMode(context: any, event: any) {
8390
}
8491
},
8592
topic,
93+
region,
8694
});
8795

8896
const payload: IoTMessage = {

src/ioTService.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,12 @@ async function connect(props?: {
122122
credentials,
123123
});
124124

125-
let region = props?.region;
126-
127-
if (!region && process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
128-
// it is localstack
129-
region = process.env.AWS_REGION ?? 'us-east-1';
130-
}
131-
132125
device = new iot.device({
133126
protocol: 'wss',
134127
host: endpoint,
135128
reconnectPeriod: 1,
136129
keepalive: 60,
137-
region,
130+
region: props?.region,
138131
accessKeyId: credentials?.accessKeyId,
139132
secretKey: credentials?.secretAccessKey,
140133
sessionToken: credentials?.sessionToken,

src/lambdaConnection.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const lambdasProcessingObservableMode = new Set<string>();
1313
*/
1414
async function connect() {
1515
topic = `${Configuration.config.debuggerId}/events`;
16+
17+
let region = Configuration.config.region;
18+
if (!region && Configuration.config.localStack) {
19+
region = process.env.AWS_REGION || 'us-east-1';
20+
Logger.verbose(
21+
`Empty region detected with LocalStack, defaulting to ${region}`,
22+
);
23+
}
24+
1625
ioTServiceConnection = await IoTService.connect({
1726
onMessage: onMessageFromLambda,
1827
topic,

0 commit comments

Comments
 (0)