AWS Builder Center
Listening to the Invisible City: Turning Sensor Signals into Intelligence | Part 2

Listening to the Invisible City: Turning Sensor Signals into Intelligence | Part 2

How can thousands of urban sensors communicate with AI? Explore MQTT, AWS IoT Core, Kinesis, Lambda, and Python to transform continuous city sensor signals into meaningful real-time intelligence.

Series: THE CITY THAT CAN FEEL: Building an Artificial Nervous System for Smart Cities Using AWS (7 articles)

  1. 2
    Listening to the Invisible City: Turning Sensor Signals into Intelligence | Part 2 This article
THE CITY THAT CAN FEEL | PART 02/07
Listening to the Invisible City: Turning Sensor Signals into Intelligence Using AWS
1. Introduction: A city is constantly speaking. Are we listening?
Every second, a city generates thousands of signals.
A traffic sensor detects vehicle movement. A water-level sensor records changes in drainage systems. An air quality monitor measures environmental conditions. A noise sensor captures sound levels. Electricity monitoring devices report consumption patterns.
These signals are continuously generated, but collecting them does not automatically make a city intelligent.
The real challenge is understanding how to capture, transmit, process, and interpret information from thousands of distributed devices.
Imagine a city with 10,000 connected sensors.
Each sensor produces data at regular intervals. Some generate readings every few seconds, while others transmit only when an event occurs.
How do we receive all this information?
How do we process it without losing important events?
How can we identify an unusual reading while the data is still arriving?
This is where Internet of Things (IoT) architecture and real-time data engineering become important.
In Part 1, we introduced the concept of an artificial nervous system for smart cities.
In this second episode, we will explore its communication and sensory infrastructure using AWS.
Our central objective is simple:
Transform continuous sensor signals into organized, meaningful, and actionable information.
2. Understanding the urban sensory network
Before building the architecture, let's identify what the city needs to sense.
A proposed urban sensory network can contain multiple categories of devices.
A. Environmental sensors
These devices monitor:
- Air quality - Temperature - Humidity - Noise levels - Weather conditions
Example: An air quality sensor periodically sends particulate matter measurements to the cloud.
B. Traffic sensors
These devices can monitor:
- Vehicle counts - Average speed - Traffic density - Road occupancy - Congestion indicators
Example: A roadside monitoring system detects an increase in vehicle density.
C. Water infrastructure sensors
These devices can monitor:
- Water levels - Pipeline pressure - Flow rates - Reservoir levels - Leakage indicators
Example: A drainage sensor reports an unusual rise in water level.
D. Energy monitoring devices
These devices can provide information about:
- Electricity consumption - Voltage - Current - Power usage - Equipment operating conditions
The important design principle is that all these sensors may produce different types of data.
Our platform needs a consistent way to identify, transmit, and organize them.
3. How do sensors communicate? Understanding MQTT
One of the most important concepts in IoT engineering is MQTT.
MQTT stands for Message Queuing Telemetry Transport.
It is a lightweight messaging protocol designed for communication between devices and applications, including resource-constrained devices.
MQTT follows a publish/subscribe model.
There are three important components:
Publisher: The device that sends a message.
Broker: The messaging service that receives and routes messages.
Subscriber: The application or device interested in receiving messages.
Consider a water-level monitoring sensor.
It publishes a message to:
city/water/zone-a/sensor-001
An application subscribed to the appropriate topic can receive that message.
Similarly, a noise monitoring device might publish to:
city/environment/noise/sensor-015
This allows different device categories to use organized communication channels.
Why MQTT is useful
- Lightweight communication - Publish/subscribe messaging - Support for constrained devices - Quality of Service options - Flexible topic-based routing
MQTT is particularly useful when a large number of devices need to transmit information without maintaining separate direct connections to every consuming application.
AWS IoT Core supports MQTT communication, including MQTT 3.1.1 and MQTT 5.0, with documented service-specific differences. <Cite refs={["turn628251search8","turn628251search13"]}/>
4. Proposed AWS architecture: From sensor to cloud
Now let's design the second stage of our artificial nervous system.
The proposed data flow contains five main components:
1. Sensor devices 2. AWS IoT Core 3. Amazon Kinesis Data Streams 4. AWS Lambda 5. Amazon S3
Layer 1: Sensor devices
Sensors collect information from the physical environment.
For a prototype, we do not need thousands of physical devices.
We can simulate sensor readings using Python.
Each sensor should have a unique identifier and a consistent message format.
For example:
{ "sensor_id": "WATER_001", "sensor_type": "water_level", "zone": "ZONE_A", "value": 82.5, "unit": "cm", "timestamp": "2026-11-10T07:00:00Z" }
This is illustrative sensor data, not an actual city measurement.
The identifier, timestamp, measurement, and unit help downstream systems interpret the reading.
Layer 2: AWS IoT Core — The city's communication gateway
AWS IoT Core provides secure connectivity between IoT devices and AWS services.
In our proposed architecture:
1. Each registered device connects to AWS IoT Core. 2. The device publishes a sensor message using MQTT. 3. The message is received on an appropriate topic. 4. An AWS IoT rule evaluates the incoming message. 5. The rule forwards the data to the selected destination.
For example, we can use a topic structure such as:
city/{zone}/{sensor_type}/{sensor_id}
Example:
city/zone-a/water-level/WATER_001 city/zone-b/noise/NOISE_002 city/zone-c/air-quality/AIR_003
This structure makes it easier to organize and filter messages.
Layer 3: AWS IoT Rules — Routing sensor information
How do we decide where incoming messages should go?
AWS IoT Rules can evaluate MQTT messages and route selected data to supported AWS services.
For our proposed platform, a rule can forward relevant messages to Amazon Kinesis Data Streams.
An illustrative IoT SQL rule:
SELECT sensor_id, sensor_type, zone, value, unit, timestamp FROM 'city/+/+/+'
This example selects the specified fields from matching MQTT topics. A production rule should also validate the payload and filter out invalid or unwanted readings.
AWS IoT Rules can route device messages to services such as Kinesis, Lambda, Amazon S3, and Amazon DynamoDB. <Cite refs={["turn628251search3"]}/>
Layer 4: Amazon Kinesis Data Streams — Handling continuous information
Imagine thousands of devices publishing sensor readings simultaneously.
Processing each message through a separate synchronous request may become difficult to manage.
Amazon Kinesis Data Streams provides a service for collecting and processing streaming data records in real time.
Think of it as a continuous data pipeline.
Its main concepts include:
- Producers: Applications or devices that write records. - Streams: Collections of incoming records. - Shards: Units that provide stream capacity. - Consumers: Applications that read and process records.
In our proposed architecture:
IoT Sensors | v AWS IoT Core | v AWS IoT Rules | v Amazon Kinesis Data Streams | v Data Consumers
Multiple consumers can use the same stream for different processing purposes.
For example:
- One consumer stores historical readings. - Another performs anomaly detection. - Another updates operational monitoring dashboards.
This separation helps the system evolve without requiring every application to communicate directly with every sensor.
Kinesis Data Streams supports real-time ingestion and consumption through its stream and shard architecture. <Cite refs={["turn628251search1","turn628251search2"]}/>
Layer 5: AWS Lambda — Turning messages into structured information
Once messages enter Kinesis, we need a processing component.
AWS Lambda can consume records from Kinesis Data Streams using an event source mapping.
Lambda reads records in batches and invokes the function to process them.
A processing function could:
1. Decode the incoming record. 2. Validate the sensor identifier. 3. Check the measurement type. 4. Verify that the value is numeric. 5. Add processing metadata. 6. Route valid and invalid records appropriately.
Example:
import json import base64
def lambda_handler(event, context):
for record in event\["Records"]:

payload = base64.b64decode(
record\["kinesis"]\["data"]
)

sensor\_data = json.loads(payload)

sensor\_id = sensor\_data.get("sensor\_id")
value = sensor\_data.get("value")
sensor\_type = sensor\_data.get("sensor\_type")

if not sensor\_id or not isinstance(value, (int, float)):
print("Invalid sensor record:", sensor\_data)
continue

print(\{
"sensor\_id": sensor\_id,
"sensor\_type": sensor\_type,
"value": value,
"status": "VALID"
})

return \{
"statusCode": 200,
"message": "Batch processed"
}
This is a simplified processing example. It logs validated records; a production implementation should also persist them, handle invalid messages, and emit appropriate metrics.
One important engineering detail: Lambda event source mappings can process records at least once, so duplicate processing is possible. Design processing functions to be idempotent where duplicate events could cause problems. <Cite refs={["turn628251search0","turn628251search9"]}/>
Layer 6: Amazon S3 — Preserving the city's digital history
Real-time information is useful, but historical information is equally important.
Without historical records, we cannot reliably compare current conditions with previous patterns.
Amazon S3 can store raw and processed sensor data.
A possible storage structure:
city-intelligence/ │ ├── raw-data/ │ ├── traffic/ │ ├── water/ │ ├── noise/ │ └── air-quality/ │ ├── processed-data/ │ ├── aggregated-data/ │ └── evaluation-data/
For larger datasets, organize records by date, zone, and sensor type.
For example:
raw-data/water/year=2026/month=11/day=10/
This organization can support later analytics and machine learning workflows.
The original readings should be retained according to an appropriate data-retention policy.
5. Practical implementation: Simulating an urban sensor network with Python
We can begin exploring this architecture without purchasing physical sensors.
Let's create a small Python-based sensor simulator.
The following program generates readings from three hypothetical urban sensors.
import random import json import time from datetime import datetime, timezone
sensors = [ { "sensor_id": "WATER_001", "sensor_type": "water_level", "zone": "ZONE_A", "unit": "cm" }, { "sensor_id": "NOISE_002", "sensor_type": "noise", "zone": "ZONE_B", "unit": "dB" }, { "sensor_id": "AIR_003", "sensor_type": "air_quality", "zone": "ZONE_C", "unit": "index" } ]
def generate_reading(sensor):
if sensor\["sensor\_type"] == "water\_level":
value = round(random.uniform(20, 100), 2)

elif sensor\["sensor\_type"] == "noise":
value = round(random.uniform(35, 95), 2)

else:
value = round(random.uniform(10, 200), 2)

return \{
"sensor\_id": sensor\["sensor\_id"],
"sensor\_type": sensor\["sensor\_type"],
"zone": sensor\["zone"],
"value": value,
"unit": sensor\["unit"],
"timestamp": datetime.now(
timezone.utc
).isoformat()
}
while True:
for sensor in sensors:

reading = generate\_reading(sensor)

print(json.dumps(reading, indent=2))

print("-" \* 50)

time.sleep(5)
This simulator produces illustrative sensor measurements every five seconds.
It does not connect to AWS yet. It gives us a controlled source of test data.
How could we connect this simulator to AWS?
There are two useful development paths.
Path A: Simulate actual IoT communication
Use an AWS IoT Device SDK and an IoT Thing configured with the required certificates and permissions.
The simulator publishes MQTT messages to AWS IoT Core.
The AWS IoT Rule forwards the selected messages to Kinesis.
Path B: Test the streaming pipeline independently
Use the AWS SDK for Python, Boto3, to send simulated records directly to a Kinesis stream using "PutRecord".
This tests Kinesis ingestion and downstream processing without first configuring the MQTT device connection.
These are alternative testing approaches. Path B does not test the AWS IoT Core communication layer.
6. What happens when sensor readings become unusual?
Let's consider a hypothetical water-level sensor.
Suppose it reports:
Reading 1: 45 cm Reading 2: 48 cm Reading 3: 51 cm Reading 4: 79 cm Reading 5: 86 cm
The readings have increased significantly.
A simple threshold-based application could flag values above a configured threshold.
However, an increase does not automatically mean a flood is occurring.
The system should consider:
- Sensor calibration - Location-specific normal ranges - Recent rainfall - Historical readings - Measurement reliability - Other nearby sensor readings
This is where the data pipeline becomes the foundation for intelligent analysis.
In Part 3, we will explore how machine learning can help identify unusual patterns before they become major problems.
7. Challenges in building a city-scale sensor network
Device connectivity
Sensors may lose connectivity due to network issues, power failures, or physical damage.
Data quality
Faulty sensors can report incorrect measurements.
Message duplication
Network retries and stream processing behavior can result in duplicate records.
Data ordering
Events may arrive late or out of order. Preserve event timestamps and design processing logic to handle this.
Scalability
A system designed for 100 sensors may not behave the same way with 100,000 sensors.
Capacity planning, partition keys, stream throughput, and consumer performance matter.
Security
Every device needs appropriate identity and permissions. Use secure connections, certificate management, least-privilege policies, and monitoring.
Cost management
Message frequency, device count, stream capacity, storage volume, and retention requirements influence cost.
A production design must estimate these factors rather than assuming that a cloud architecture is automatically inexpensive.
8. What have we designed in Part 2?
We have explored how an urban sensory network could operate.
The proposed pipeline is:
Sensors → MQTT → AWS IoT Core → IoT Rules → Kinesis → Lambda → Amazon S3
This architecture provides a foundation for:
- Receiving continuous sensor information. - Routing messages to different applications. - Processing events in batches. - Preserving historical data. - Preparing information for machine learning.
The important point is that we are not simply connecting sensors to a cloud database.
We are designing the data communication layer of an intelligent city.
9. What comes next? Part 3 of the series
We can now collect information from the city.
But there is another important question:
How can a city distinguish normal behavior from the early signs of a problem?
For example:
- Is a rising water level normal after rainfall? - Is a sudden increase in noise unusual for that location? - Is an electricity consumption pattern abnormal? - Is a traffic slowdown an isolated event or the beginning of congestion?
In Part 3, we will explore:
Detecting Problems Before They Become Emergencies: Building an AI-Based Urban Anomaly Detection System.
We will examine:
- Anomaly detection techniques. - Time-series analysis. - Feature engineering. - Machine learning models. - Amazon SageMaker AI. - Early-warning system design. - Model evaluation and false alarms.
The city has started speaking.
Now we need to teach the system how to recognize when something is unusual.
THE CITY THAT CAN FEEL — Seven days. Seven technical deep dives. One intelligent city vision.


References and further reading

Disclaimer: This article presents a proposed architecture and illustrative Python examples for educational purposes. It does not claim a deployed city-scale system or measured operational improvements. Sensor readings are simulated, and real-world deployments require device testing, security validation, infrastructure approval, and human oversight.

Series: THE CITY THAT CAN FEEL: Building an Artificial Nervous System for Smart Cities Using AWS (7 articles)

  1. 2
    Listening to the Invisible City: Turning Sensor Signals into Intelligence | Part 2 This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article