# alvurama/iniciando_aws_iot architecture

> Architecture diagram of the GitHub repository alvurama/iniciando_aws_iot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alvurama/iniciando_aws_iot
- Repository: https://github.com/alvurama/iniciando_aws_iot

## Overview

##### Project Type and Purpose
- This is an end-to-end AWS IoT tutorial repository that walks through three exercises:
- Exercise 1: Simulate an MQTT device in Python using AWSIoTPythonSDK.
- Exercise 2: Implement a real MQTT device on NodeMCU ESP8266 using Arduino IDE.
- Exercise 3: Define AWS IoT Core rules to route incoming MQTT messages into DynamoDB, SNS (SMS/email notifications) and SQS.
- It is not a monolithic web app or microservice suite, but rather an IoT‐focused reference architecture showing how devices connect securely over MQTT, and how the cloud ingests and processes streams of IoT data.

##### File Structure Analysis
- Top-level artifacts:
- README.md and supporting markdown docs (NodeMCU_ESP8266.md, instalarOpenSSL.md) for setup.
- ejercicio1.py (and duplicate under ejericio1/) – the Python simulator.
- ejercicio2.txt – the Arduino C++ sketch for the ESP8266.
- arduino/ folder (three sample sensor sketches) shows evolution of firmware.
- libreria/NTPClient contains a custom fork of the NTP Client library used on the ESP8266 to timestamp messages.

##### Main Components to Capture
A. Devices (Edge Components)
– Python Simulator (ejercicio1.py) running on desktop, using AWSIoTPythonSDK.
– NodeMCU ESP8266 device running Arduino sketch, with SPIFFS‐stored DER certificates and libraries: FS.h, ESP8266WiFi, PubSubClient, NTPClient.
B. Security Artifacts
– X.509 Certificates (certificate.pem, privateKey.pem, rootCA.pem) converted to DER for the ESP8266.
– AWS IoT Thing object (“objeto1”), associated policy (least privilege * for tutorial), attached certificate.
C. AWS IoT Core
– MQTT Broker endpoint (e.g., data.iot.us-west-2.amazonaws.com:8883).
– Rules Engine that evaluates incoming topics (“data”) against SQL queries.
D. AWS Back-End Services
– DynamoDB table “iot-prueba” for all messages.
– Amazon SNS Topic “SNSAlerta” with SMS/email subscriptions.
– Amazon SQS Queue “ColaAlertaIot” subscribed to the SNS topic (for durable message buffering).
E. AWS Console / MQTT Test Client
– Cloud-side test MQTT client under “Test” to subscribe to topic “data” and validate payload.

##### Relationships and Data Flow
1. Edge devices (Python app or ESP8266) →(MQTT over TLS with X.509 certs)→ AWS IoT Core
2. On receipt of messages on topic “data”:
- Rule 1: INSERT ALL payload fields → DynamoDB (“iot-prueba”)
- Rule 2: IF payload.Temperatura > 40 → publish raw alert message to SNSAlerta
3. SNSAlerta → delivers SMS/email → fan-out to SQS queue (ColaAlertaIot)
4. (Optional) Cloud user inspects DynamoDB table via console or polls SQS for downstream processing

##### Architectural Patterns and Design Principles
- Publish/Subscribe (MQTT broker) decouples producers (devices) from consumers (cloud rules).
- Event-Driven Rules Engine routes messages without custom code.
- Secure IoT: mutual TLS authentication with device certificates; certificate and policy lifecycle managed in AWS IoT Core.
- Separation of concerns:
- Edge code (device firmware & simulation) vs.
- Cloud ingestion & storage vs.
- Notification & queueing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Edge Devices
    subgraph "Edge Devices"
        py["Python Simulator"]:::devices
        esp["ESP8266 Device"]:::devices
    end

    %% AWS IoT Core
    iot["AWS IoT Core\n(MQTT Broker\nendpoint: data.iot.us-west-2.amazonaws.com:8883)"]:::cloud

    %% AWS Back-End
    dynamo["DynamoDB Table\niot-prueba"]:::db
    sns["SNS Topic\nSNSAlerta"]:::sns
    sms["SMS/Email Subscription"]:::ext
    sqs["SQS Queue\nColaAlertaIot"]:::queue

    %% Data Flow
    py -->|"MQTT/TLS (8883)\npublish('data', JSON)"| iot
    esp -->|"MQTT/TLS (8883)\npublish('data', JSON)"| iot

    iot -->|"INSERT ALL\nSQL INTO 'data'"| dynamo
    iot -->|"IF payload.Temperatura>40\npublish to SNSAlerta"| sns

    sns -->|"SMS/Email notifications"| sms
    sns -->|"Fan-out"| sqs

    %% Click Events for Mapped Components
    click py "https://github.com/alvurama/iniciando_aws_iot/blob/master/ejercicio1.py"
    click py "https://github.com/alvurama/iniciando_aws_iot/blob/master/ejericio1/ejercicio1.py"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/ejercicio2.txt"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/arduino/con_sensor/con_sensor.ino"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/arduino/con_sensor2/con_sensor2.ino"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/arduino/ejercicio2_sensor/ejercicio2_sensor.ino"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/NTPClient.cpp"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/NTPClient.h"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/NTPClient_2.h"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/library.json"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/library.properties"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/examples/Basic/Basic.ino"
    click esp "https://github.com/alvurama/iniciando_aws_iot/blob/master/libreria/NTPClient/examples/Advanced/Advanced.ino"

    %% Styles
    classDef devices fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
    classDef cloud fill:#bbeeff,stroke:#036,stroke-width:2px
    classDef db fill:#cfecec,stroke:#065,stroke-width:2px
    classDef sns fill:#fcefb6,stroke:#aa7,stroke-width:2px
    classDef queue fill:#e0e0e0,stroke:#777,stroke-width:2px
    classDef ext fill:#ffdada,stroke:#a00,stroke-width:2px
```
