@uhuru/awsiot-thing-creator
Installing
npm install @uhuru/awsiot-thing-creator
yarn add @uhuru/awsiot-thing-creator
Environment Variables
Supported environment variables:
ENV DESCRIPTION
AWS_ACCESS_KEY_ID AWS access key ID
AWS_SECRET_ACCESS_KEY AWS secret access key
AWS_IOT_REGION AWS IoT region
AWS_IOT_THING_NAME The name of the AWS IoT thing to be created
npm start
This library can be called by npm-start command.
$ npm start -- --aws-access-key-id=hoge --aws-secret-access-key=foo --aws-iot-region=bar --aws-iot-thing-name=buzz --thing-attribute-payload={\"attributes\":{\"string1\":\"string2\"}} --thing-type-name=Device
Note that you need to build this package before running npm start.
$ npm run build
The arguments
Argument | Required | Description | Example |
---|
--aws-access-key-id | Yes | AWS access key ID | AKIAJWWCHDEPQJD456PQ |
--aws-secret-access-key | Yes | AWS secret access key | 6qtl9JJ90ue5CMeHSJKm1I4iRRwKOQKLCpzt9Y94 |
--aws-iot-region | Yes | AWS IoT region | us-west-2 |
--aws-iot-thing-name | Yes | The name of the AWS IoT thing to be created | enebular-agent-test |
--thing-attribute-payload | No | The attribute payload | {\"attributes\":{\"string1\":\"string2\"} |
--thing-type-name | No | The name of the thing type | Device |
For more details about above arguments, please refer to AWS document
IoT Client - AWS SDK for JavaScript v3
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
}
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
}