Block 0 — Fleet Provisioning: How Devices Get Into IoT Core¶
Duration: 45 min
Type: Conceptual walkthrough + console tour. No live provisioning — the 3 devices are already registered.
The Four Provisioning Approaches¶
| Approach | Who owns the CA | When does the device get its permanent cert | Best for |
|---|---|---|---|
| Single-thing / manual | AWS IoT CA | Before the device ships | Lab devices, one-offs |
| Provisioning by trusted user | AWS IoT CA | At commissioning time — authenticated actor calls the API on demand | Any scale; natural fit when a commissioning workflow already exists |
| Provisioning by claim | AWS IoT CA | On first cloud connection — device exchanges a shared claim cert for a permanent cert | Automated deployments; no human commissioning step |
| JITP / JITR | You own the CA — cert signed by your PKI | Before the device ships — burned in at the factory | Hardware with factory-provisioned identity (HSM, secure enclave) |
The sharpest distinction
By-claim and JITP/JITR both look like "device self-registers on first connection," but they differ fundamentally. With by-claim the device arrives as a blank slate and AWS mints its identity on first boot. With JITP/JITR the device already holds its permanent identity from the factory floor — AWS just learns about it when it first connects.
AWS IoT CA vs. JITP — it's about the factory's trust boundary, not the cert
You can also give a device a permanent, unique identity at manufacturing time using the AWS IoT CA — mint a per-device cert (via CreateCertificateFromCsr, so the private key never leaves the secure element) and flash it in. That produces an identity that is cryptographically just as strong as a JITP identity signed by your own CA. So JITP is not "the more secure cert."
The biggest real difference is whether the location where the image is flashed onto the device has access to your AWS environment:
- AWS IoT CA at the factory — the flashing station must hold live credentials to your AWS account and call AWS IoT per unit. That extends your account's trust boundary onto the factory floor (often a third-party contract manufacturer) and couples line throughput to your cloud being reachable.
- JITP with a CA you own (e.g. AWS Private CA) — the factory signs certs locally with the CA, never touching your AWS account. The manufacturer can even run their own AWS Private CA in their own AWS account; you just register that CA's public cert in your IoT account. No cross-account credentials, no per-unit call to your cloud.
So the trade-off is a process / trust-boundary property, not a property of the identity. If the factory is trusted with your AWS credentials and has reliable connectivity (e.g. it's your own facility), minting via AWS IoT CA is a sound, equally-secure design with less machinery. JITP earns its keep when you can't or won't put your AWS credentials in the factory, need the line to be independent of your cloud, or must be your own root of trust for compliance/portability.
Claim Flow Walkthrough¶
This is what happened when the CDK stack deployed the 3 devices:
-
CDK creates a provisioning template (
participant-stack.ts) — defines what IoT resources to create when a device presents a claim cert (Thing name derived from EC2 instance ID, policy attached, permanent cert activated)View CDK source — provisioning template
const provisioningTemplate = new CfnProvisioningTemplate(this, "ProvisioningTemplate", { templateName: `${deploymentId}-provisioning`, description: `Fleet provisioning template for deployment ${deploymentId}`, enabled: true, provisioningRoleArn: provisioningRole.roleArn, preProvisioningHook: { targetArn: preProvisionLambda.functionArn, payloadVersion: "2020-04-01", }, templateBody: JSON.stringify({ Parameters: { ThingName: { Type: "String" }, SerialNumber: { Type: "String" }, }, Resources: { certificate: { Type: "AWS::IoT::Certificate", Properties: { CertificateId: { Ref: "AWS::IoT::Certificate::Id" }, Status: "ACTIVE", }, }, thing: { Type: "AWS::IoT::Thing", Properties: { ThingName: { Ref: "ThingName" }, AttributePayload: { deploymentId: deploymentId, }, ThingGroups: [`${deploymentId}-devices`], }, OverrideSettings: { AttributePayload: "MERGE", ThingGroups: "REPLACE", }, }, policy: { Type: "AWS::IoT::Policy", Properties: { PolicyName: `workshop-${deploymentId}-device-policy`, }, }, }, }), }); // The template body references preProvisionLambda.functionArn, so CDK orders // it after the *function* — but IoT validates the pre-provisioning hook at // template-create time by invoking that Lambda, which requires the // AllowIoTInvoke permission to already exist. That permission is a sibling // resource with no reference link, so without an explicit dependency it's a // race: if the template is created before the permission, IoT returns // "Access denied during lambda validation" and the stack rolls back. // Depend on the Lambda construct so all its children (including the // permission) are created first. provisioningTemplate.node.addDependency(preProvisionLambda); -
CDK creates a claim certificate — a shared credential with a tightly scoped IoT policy: can only connect and call
$aws/certificates/create/*and$aws/provisioning-templates/{templateName}/provision/* -
CDK stores the claim cert in Secrets Manager — scoped to the deployment. EC2 instances use an IAM instance profile with
secretsmanager:GetSecretValuerestricted to that specific secret ARNWhy not user data?
EC2 user data is readable in plaintext by anyone with
ec2:DescribeInstanceAttribute— effectively not secret. Secrets Manager provides fine-grained access control and CloudTrail audit logging. -
On first boot: the user data script calls
aws secretsmanager get-secret-value, writes the claim cert to disk, and starts the Device Client. The Device Client callsCreateKeysAndCertificate→RegisterThing→ IoT Core creates the Thing and issues a permanent cert - Claim cert files are deleted immediately after
RegisterThingsucceeds -
Pre-provisioning hook Lambda runs before IoT Core acts on the request. In this workshop it is log-only — it records each provisioning attempt (deployment, Thing name, serial) for observability and always allows provisioning. This lets participants register their own lab devices (see below), which have no EC2 instance ID to validate against.
View CDK source — pre-provisioning hook
// Log-only pre-provisioning hook: it records every provisioning attempt for // observability but always allows registration. Participants register their // own lab devices (e.g. a Raspberry Pi over SSH — see scripts/register-device-ssh.sh), // which have no EC2 instance ID, so the hook must not gate on EC2 identity. // The shared claim certificate (delivered to a device by an authenticated // operator) is what controls who can register. const preProvisionLambda = new LambdaFn(this, "PreProvisionHook", { functionName: `workshop-${deploymentId}-pre-provision`, runtime: Runtime.NODEJS_22_X, architecture: Architecture.ARM_64, handler: "index.handler", code: Code.fromInline(` const DEPLOYMENT_ID = "${deploymentId}"; exports.handler = async (event) => { const thingName = event.parameters?.ThingName; const serialNumber = event.parameters?.SerialNumber; // Log-only: record the attempt for observability, then always allow. console.log(JSON.stringify({ msg: "provisioning attempt", deploymentId: DEPLOYMENT_ID, thingName: thingName ?? null, serialNumber: serialNumber ?? null, })); return { allowProvisioning: true }; }; `), role: preProvisionLambdaRole, timeout: Duration.seconds(10), }); preProvisionLambda.addPermission("AllowIoTInvoke", { principal: new ServicePrincipal("iot.amazonaws.com"), });Teaching point
The hook is the control point, and what you enforce there is a policy choice. A shared claim cert is a wide key — any holder can attempt provisioning. A production hook is where you'd narrow that surface: verify the device against an authoritative source (a device registry, a manufacturing database) and reject unknown or duplicate devices. This workshop deliberately runs it log-only so you can register any device you bring; the shared claim cert (delivered to a device by an authenticated operator) is then the only gate.
Register your own device
You can register a device you own — a Raspberry Pi, or any Linux host — into your slot over SSH using scripts/register-device-ssh.sh. It runs the same by-claim flow described above. See Register your own device.
Trusted User — The Production-Ready Alternative¶
Provisioning by trusted user maps directly onto the Cognito user pool already deployed in this workshop:
- Field engineer authenticates to the management UI via Cognito
- AppSync mutation → Lambda calls
CreateProvisioningClaimvia IoT management API - A one-time-use claim cert is returned and handed to the device
- Device runs the same
RegisterThingflow
| By claim | By trusted user | |
|---|---|---|
| Human required at install | No | Yes — authenticated via Cognito |
| Per-provisioning audit trail | No (shared cert) | Yes — Cognito identity + CloudTrail per device |
| Risk surface | Shared static cert must be kept secret | No shared secret; risk isolated to individual accounts |
| Works without cloud at factory | Yes | No — needs live API call |
| Fits this workshop's Cognito pool | No | Yes — directly |
By-claim is used here purely because the CDK deployment is fully automated with no human commissioning step.
Console Tour¶
Open each link and walk through what's shown:
- IoT Core → Connect → Fleet Provisioning → show the provisioning template JSON
- IoT Core → Security → Certificates → show the claim cert (status:
ACTIVE, policy: provisioning-only) - IoT Core → Manage → Things → open one device → show its permanent cert and attached policy
- IoT Core → Security → Policies → compare the claim cert policy (3 statements) vs the device operational policy (publish/subscribe on
edge/ws-slot00/#and shadow topics)