This is a CDK construct that creates an AWS IoT Core Thing with a certificate and policy using aws-sdk-js-v3.
Cloudformation does not support creating a certificate for an IoT Thing, so this construct uses the AWS SDK to create a certificate and attach it to the Thing.
This construct is a modified version of this excellent construct (cdk-iot-core-certificate) to work with aws-sdk-js-v3.
npm i cdk-iot-core-certificates-v3
import * as s3 from 'aws-cdk-lib/aws-s3';
import { ThingWithCert } from 'cdk-iot-core-certificates-v3';
declare const saveFileBucket: s3.IBucket;
const { thingArn, certId, certPem, privKey } = new ThingWithCert(this, 'MyThing', {
// The name of the thing
thingName: 'MyThing',
// Whether to save the certificate and private key to the SSM Parameter Store
saveToParamStore: true,
// The prefix to use for the SSM Parameter Store parameters
paramPrefix: 'test',
// The bucket to save the certificate and private key to
// Both files are saved at `{thingName}/{thingName}.private.key` and `{thingName}/{thingName}.cert.pem`
// If not provided, the certificate and private key will not be saved
saveFileBucket,
});