Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Oct 22, 2024
1 parent 7693e5d commit 98ce354
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# replace this
# 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](https://github.com/aws/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)](https://github.com/devops-at-home/cdk-iot-core-certificates) to work with aws-sdk-js-v3.

## Installation

```bash
npm i cdk-iot-core-certificate-v3
```

## Usage

```typescript
import { ThingWithCert } from 'cdk-iot-core-certificate-v3';

const thing = new ThingWithCert(this, 'MyThing', {
thingName: 'MyThing',
saveToParamStore: true,
paramPrefix: 'test',
});

const thingArn = thing.thingArn;
const certId = thing.certId;
const certPem = thing.certPem;
const privateKey = thing.privKey;
```
34 changes: 34 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,51 @@ import { CfnParameter } from 'aws-cdk-lib/aws-ssm';
import { Provider } from 'aws-cdk-lib/custom-resources';
import { Construct } from 'constructs';

/**
* Properties of ThingWithCert construct
*/
export interface ThingWithCertProps extends ResourceProps {
/**
* The name of the thing
*/
readonly thingName: string;

/**
* Whether to save the certificate and private key to AWS Systems Manager Parameter Store
*/
readonly saveToParamStore?: boolean;

/**
* The prefix for the parameter store path
*/
readonly paramPrefix?: string;
}

/**
* A CDK Construct for creating an AWS IoT Core thing with a certificate
*/
export class ThingWithCert extends Construct {

/**
* The ARN of the thing
*/
public readonly thingArn: string;

/**
* The ID of the certificate
*/
public readonly certId: string;

/**
* The certificate PEM
*/
public readonly certPem: string;

/**
* The private key
*/
public readonly privKey: string;

constructor(scope: Construct, id: string, props: ThingWithCertProps) {
super(scope, id);

Expand Down

0 comments on commit 98ce354

Please sign in to comment.