Skip to main content

CDK Construct for AWS IoT Core certificates and things

Project description

AWS IoT Core Thing with Certificate v3 construct

This is a CDK construct that creates an AWS IoT Core Thing with a certificate and policy using aws-sdk-js-v3.

elements

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.

View on Construct Hub Open in Visual Studio Code npm version Build Status Release Status License Downloads npm downloads

Installation

npm i cdk-iot-core-certificates-v3

Usage

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,
});

If you want to create multiple things and save certificates and private keys to the same bucket, you should not use saveFileBucket prop and save them at once by BucketDeployment construct.

This is because the each saveFileBucket prop will share a custom resource for each thing, which will cause the deployment to fail.

import * as s3 from 'aws-cdk-lib/aws-s3';
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
import { ThingWithCert } from 'cdk-iot-core-certificates-v3';

const thingNames = ['Thing1', 'Thing2', 'Thing3'];
const certBucket = new s3.Bucket(this, "CertBucket");
const sources: s3deploy.ISource[] = [];

thingNames.forEach((thingName, index) => {
  const { certPem, privKey } = new ThingWithCert(this, `Thing${index}`, {
    thingName,
    saveToParamStore: true,
  });
  sources.push(
    s3deploy.Source.data(`${thingName}/${thingName}.cert.pem`, certPem),
    s3deploy.Source.data(`${thingName}/${thingName}.private.key`, privKey)
  );
});

// Deploy the certificate and private key to the S3 bucket at once
new s3deploy.BucketDeployment(this, "DeployCerts", {
  sources,
  destinationBucket: certBucket,
});

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk_iot_core_certificates_v3-0.0.14.tar.gz (14.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_iot_core_certificates_v3-0.0.14-py3-none-any.whl (14.5 MB view details)

Uploaded Python 3

File details

Details for the file cdk_iot_core_certificates_v3-0.0.14.tar.gz.

File metadata

File hashes

Hashes for cdk_iot_core_certificates_v3-0.0.14.tar.gz
Algorithm Hash digest
SHA256 4305c22805a7282a0bab6b5a9b0a787f4947489f6de773ee52a7327475060d58
MD5 f9b83fef346c6ec1478efb15b5899f76
BLAKE2b-256 89f885c442adef1305488dc810c66f8e63a33c15cd130a2709919ff13ea38e32

See more details on using hashes here.

File details

Details for the file cdk_iot_core_certificates_v3-0.0.14-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_iot_core_certificates_v3-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 d10f1d0834e0a456b97c24b52d65b187cbfaa083967904990c70b52c08517e67
MD5 03af0c4a0d0363e7b86a10f18e73d89b
BLAKE2b-256 8acbb3e38ea55d632dd1188b0b171edd28b5b2ffe4678260f0923c7d08e97d52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page