@uhuru/awsiot-thing-creator
v1.2.2
Published
- `npm install @uhuru/awsiot-thing-creator` - `yarn add @uhuru/awsiot-thing-creator`
Downloads
14
Keywords
Readme
@uhuru/awsiot-thing-creator
Installing
npm install @uhuru/awsiot-thing-creator
yarn add @uhuru/awsiot-thing-creator
ECMAScript Modules
This library can also be used as ECMAScript Module.
import { AWSIoTThingCreator } from '@uhuru/awsiot-thing-creator';
const attributePayload = {
atrributes: {
key: "value"
}
}
const config = {
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
awsIotRegion: process.env.AWS_IOT_REGION,
thingName: "enebular-agent-test",
thingTypeName: "Device",
thingAttributePayload: attributePayload
}
// Check required variables
if (
!config.awsAccessKeyId ||
!config.awsIotRegion ||
!config.awsSecretAccessKey ||
!config.thingName
) {
throw new Error(`
A configuration is required.
Verify that these required environment variables are set:
- AWS_ACCESS_KEY_ID
- AWS_IOT_REGION
- AWS_SECRET_ACCESS_KEY
- awsIotThingName
`)
}
const creator = new AWSIoTThingCreator(config)
const result = await creator.createThing().catch((error) => {
console.error(error.message)
throw new Error('Failed to create thing.')
})
return {
config: result.config,
rootPem: result.rootPem,
clientPem: result.clientPem,
privateKey: result.privateKey
}