AWS CDK - how to create bulk thing with certs using CDK

Viewed 60

i can create thing, policy, certificate and connect altogether with these steps similar to https://github.com/aws/aws-cdk/issues/19303

But I want to do that with bulk thing creation, create certs and with policy (have created policy etc)

How do i achieve with CDK ?

i tried using provisioning template, but i am a bit unsure about that.

my code

const iotAssumeRoleWithCertificatePolicy = new iot.CfnPolicy(this, 'iotAssumeRoleWithCertificatePolicy', {
      policyName: 'iotAssumeRoleWithCertificatePolicy',
      policyDocument: {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Effect": "Allow",
            "Action": "iot:AssumeRoleWithCertificate",
            "Resource": iotRoleAlias.roleArn.toString(),
          }
        ]
      },
    });

const provisioningTemplateBody = {
      "Parameters": {
        "ThingName": {
          "Type": "String"
        },
        "CSR": {
          "Type": "String"
        },
      },
      "Resources": {
        "thing": {
          "Type": "AWS::IoT::Thing",
          "Properties": {
            "ThingName": { "Ref": "ThingName" },
            "ThingTypeName": "server-type",
            "ThingGroups": [
              "server-group",
            ]
          }
        },
        "certificate": {
          "Type": "AWS::IoT::Certificate",
          "Properties": {
            "CertificateSigningRequest": { "Ref": "CSR" },
            CertificateId: {
              Ref: 'AWS::IoT::Certificate::Id',
            },
            "Status": "ACTIVE"
          }
        },
        "policy": {
          "Type": "AWS::IoT::Policy",
          "Properties": {
            "PolicyName": iotAssumeRoleWithCertificatePolicy.toString(),
          }
        }
      }
    }

    const provisiongTemplate = new iot.CfnProvisioningTemplate(this, 'iot-provisioning-template', {
      provisioningRoleArn: iotProvisioningRole.roleArn,
      templateBody: JSON.stringify(provisioningTemplateBody),
    });
0 Answers
Related