Contents
AWS IoT Overview
AWS IoT Core provides secure, bi-directional communication between IoT devices and AWS cloud services.
Key Components:
- Device Gateway: MQTT/HTTP/WSS endpoints
- Message Broker: Pub/sub messaging
- Device Shadow: Device state persistence
- Rules Engine: Route data to AWS services
- Security: X.509 certificates, IAM policies
Account Setup
# AWS CLI - Create IoT Thing
aws iot create-thing --thing-name "ESP32_Device_001"
# Create certificate
aws iot create-keys-and-certificate \
--set-as-active \
--certificate-pem-outfile certificate.pem \
--public-key-outfile public_key.pem \
--private-key-outfile private_key.pem
# Attach policy
aws iot attach-policy \
--policy-name BasicIoTPolicy \
--target certificate_arn
Device Provisioning
#include
char AWS_IOT_ENDPOINT[] = "xxxxxxxxx.iot.us-east-1.amazonaws.com";
char certificate[] = "-----BEGIN CERTIFICATE-----...";
char private_key[] = "-----BEGIN RSA PRIVATE KEY-----...";
void setup() {
WiFi.begin(ssid, password);
AWS_IoT.begin(AWS_IOT_ENDPOINT);
AWS_IoT.setCertificate(certificate);
AWS_IoT.setPrivateKey(private_key);
if (AWS_IoT.connect("ESP32_Device_001")) {
Serial.println("Connected to AWS IoT!");
}
}
Device Shadow
// Update device shadow
String shadowPayload = "{"desired":{"temperature":25}}";
AWS_IoT.publish("$aws/things/ESP32_Device_001/shadow/update", shadowPayload);
// Subscribe to shadow updates
AWS_IoT.subscribe("$aws/things/ESP32_Device_001/shadow/update/delta");
// Shadow JSON structure
{
"state": {
"desired": {"temperature": 25},
"reported": {"temperature": 22},
"delta": {"temperature": 25}
}
}
IoT Rules Engine
-- SQL-like rule for data routing
SELECT
temperature,
humidity,
timestamp() as timestamp
FROM 'iot/sensors/+'
WHERE temperature > 30
-- Actions:
-- 1. Save to DynamoDB
-- 2. Send SNS alert
-- 3. Invoke Lambda
-- 4. Write to S3
-- 5. Forward to Kinesis
AWS Greengrass
Edge computing for local processing:
- Run Lambda functions locally
- Local message routing
- Offline operation
- ML inference at edge
Next Steps
- Set up CloudWatch monitoring
- Implement Device Defender
- Add FreeRTOS for microcontrollers
- Configure IoT Analytics
Related: Azure IoT Hub | IoT Security