Skip to content

Commit 0910194

Browse files
authored
Merge pull request #37 from ServerlessLife/use-credentials-provider-from-aws-sdk
fix: use credentials provider from aws-sdk to support all means of authentication toward aws
2 parents d434694 + 617b142 commit 0910194

File tree

5 files changed

+2222
-113
lines changed

5 files changed

+2222
-113
lines changed

listener/iot-connection.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
12
import { device } from 'aws-iot-device-sdk';
23

34
export type fragment = { id: string; index: number; count: number; data: any };
@@ -28,12 +29,18 @@ export async function getConnection(
2829
logError('No IoT endpoint could be found');
2930
throw new Error('IoT Endpoint address not found');
3031
}
32+
const region = iotEndpoint.split('.')[2];
3133

34+
const provider = fromNodeProviderChain();
35+
const credentials = await provider();
3236
const connection = new device({
3337
protocol: 'wss',
3438
host: iotEndpoint,
35-
region: process.env['AWS_REGION'],
39+
region,
3640
reconnectPeriod: 1,
41+
accessKeyId: credentials.accessKeyId,
42+
secretKey: credentials.secretAccessKey,
43+
sessionToken: credentials.sessionToken,
3744
});
3845

3946
connection.on('connect', () => {

0 commit comments

Comments
 (0)