-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 891 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { auth, iot, mqtt } from "aws-iot-device-sdk-v2";
const credentials = {
accessKeyId: "",
secretAccessKey: "",
sessionToken: "",
};
const region = "us-east-1";
const mqttEndpoint = "asbce-ats.iot.us-east-1.amazonaws.com";
const clientId = "test-" + Math.floor(Math.random() * 100000000);
const config_builder =
iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
region,
credentials_provider: auth.AwsCredentialsProvider.newStatic(
credentials.accessKeyId,
credentials.secretAccessKey,
credentials.sessionToken
),
});
config_builder.with_clean_session(false);
config_builder.with_client_id();
config_builder.with_endpoint(mqttEndpoint);
const config = config_builder.build();
console.log(`Connecting ${clientId}...`, config);
const client = new mqtt.MqttClient();
connection = client.new_connection(config);
console.log(connection);