Here’s the comprehensive solution addressing all three focus areas:
Certificate Rotation Process:
Proper certificate rotation requires these sequential steps:
- Create new certificate and keep old one ACTIVE initially
- Attach new certificate to Thing while old cert remains attached
- Attach IoT policy to new certificate
- Update device with new certificate credentials
- Verify device connects successfully with new cert
- Only then detach old certificate and mark INACTIVE
The script for step 3 (policy attachment):
for cert_arn in $(cat new_cert_arns.txt); do
aws iot attach-policy \
--policy-name DevicePolicy \
--target $cert_arn
done
IoT Policy Attachment:
Your policy must use dynamic references, not static certificate ARNs. Update your policy to use Thing-based conditions:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "arn:aws:iot:region:account:client/${iot:Connection.Thing.ThingName}"
}]
}
To fix your current situation, attach the policy to all new certificates:
aws iot list-thing-principals --thing-name device-001
# Identify new certificate ARN
aws iot attach-policy --policy-name YourPolicyName \
--target arn:aws:iot:region:account:cert/new-cert-id
Device ARN Mapping:
Verify and fix Thing-to-certificate mappings. List all principals for a Thing:
aws iot list-thing-principals --thing-name device-001
If old certificate is still attached, detach it:
aws iot detach-thing-principal \
--thing-name device-001 \
--principal arn:aws:iot:region:account:cert/old-cert-id
Immediate Recovery Steps:
- List all Things and their current certificate attachments
- For each Thing, identify the new certificate ARN
- Attach your IoT policy to each new certificate ARN
- Verify policy attachment: `aws iot list-attached-policies --target cert-arn
- Test device connection with new certificate
- Once confirmed working, detach and deactivate old certificates
Automation for Future Rotations:
Create a rotation script that handles all steps atomically:
- Generates new certificate
- Attaches to Thing (keeping old cert attached)
- Copies all policy attachments from old to new cert
- Updates device configuration
- Validates connection
- Only then removes old cert
This prevents the connection outage you’re experiencing. The key insight is that policy attachments are certificate-specific, not Thing-specific, so rotation must explicitly transfer them.