"Lake Level Advisor" it's a serverless application that give people information about lake's water level and send sms when the water level it's too low or to high.
This system may be useful to warn people in case of risk of overflowing or perhaps to inform farmers that are watering their crops with that lake's water.
We're considering a Hydrostatic pressure level sensor distributed every 25 km^2 of surface for the 5 largest italians lake.
This is gonna provide us information about the average lake's water level and information about the minimum and maximum water's level.
The IoT devices of a certain lake will provide the measures to the relative queues, after that 2 different lamda function
- Every minute, a time-triggered Serverless function calculates the average, the minimum and maximum water level for every lake(aka. every queue) and store this information in the database that can be accessed from the user as much as he like.
- Every minute, a message-triggered Serverless function calculates assert that the average water level is within a certain range otherwise, throw an ifttt applet a sms will be sent.
-
Clone the repository
git clone https://github.com/Joe-cyber/LakeLevelAdvisor
-
Launch LocalStack
docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack
-
Create a SQS queue for each shop
aws aws sqs create-queue --queue-name Garda --endpoint-url=http://localhost:4566
aws sqs create-queue --queue-name Maggiore --endpoint-url=http://localhost:4566
aws sqs create-queue --queue-name Como --endpoint-url=http://localhost:4566
aws sqs create-queue --queue-name Tresimeno --endpoint-url=http://localhost:4566
aws sqs create-queue --queue-name Bolsena --endpoint-url=http://localhost:4566
You can check that the queues has been actually created using the command:
aws sqs list-queues --endpoint-url=http://localhost:4566
-
Create the DynamoDB table
python3 settings/createTable.py
You can check that the table has been actually created using the command:
aws dynamodb list-tables --endpoint-url=http://localhost:4566
-
Populate the tables with initial data (Optional)
python3 settings/loadData.py
- Check the value of the entire database with populate tables
aws dynamodb scan --table-name Lakes --endpoint-url=http://localhost:4566
- create the zip, lambda function and attach the policy
- Create the role and attach the policy
aws iam create-role --role-name lambdarole --assume-role-policy-document file://settings/role.json --query 'Role.Arn' --endpoint-url=http://localhost:4566aws iam put-role-policy --role-name lambdarole --policy-name lambdapolicy --policy-document file://settings/policy.json --endpoint-url=http://localhost:4566
- Create the zip file
zip avgFunc.zip settings/avgFunc.py
- Create the lambda function and save the Arn
aws lambda create-function --function-name avgFunc --zip-file fileb://avgFunc.zip --handler settings/avgFunc.lambda_handler --runtime python3.6 --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
- Set up a rule to trigger the Lambda function every minute
-
Create the rule and save the Arn
aws events put-rule --name calculateAvg --schedule-expression 'rate(1 minutes)' --endpoint-url=http://localhost:4566You can check that the rule has been actually created using the command:
aws events list-rules --endpoint-url=http://localhost:4566
-
Add permissions to the rule
aws lambda add-permission --function-name avgFunc --statement-id calculateAvg --action 'lambda:InvokeFunction' --principal events.amazonaws.com --source-arn arn:aws:events:us-east-1:000000000000:rule/avgFunc --endpoint-url=http://localhost:4566 -
Add the lambda function to the rule using the JSON file
aws events put-targets --rule calculateAvg --targets file://settings/targets.json --endpoint-url=http://localhost:4566
Now every minute the function countFunc will be triggered.
- Go to https://ifttt.com/
- Create a new applet.
- Click "If This", type "webhooks" and choose the Webhooks service
- Select "Receive a web request", write "dangerous-water-level" and create "trigger".
- Click Then That, type "Android SMS integrations"
- Click Android SMS integrations and choosing the topic and the body (Pay attention, this requires that the ifttt app is installed on your phone)
- Save your key and copy it into the summary.py
- Zip the file and create the Lambda function
zip smsNotification.zip smsNotification.py
aws lambda create-function --function-name smsNotification --zip-file fileb://smsNotification.zip --handler smsNotification.lambda_handler --runtime python3.6 --role arn:aws:iam::000000000000:role/lambdarole --endpoint-url=http://localhost:4566
- Create the event source mapping
aws lambda create-event-source-mapping --function-name smsNotification --batch-size 5 --maximum-batching-window-in-seconds 60 --event-source-arn arn:aws:sqs:us-east-1:000000000000:Summary --endpoint-url=http://localhost:4566
The output should be more similar to this:

- Simulate the devices
python3 IoTDevices.py
- Wait or invoke Lambda function manually
aws lambda invoke --function-name avgFunc --payload fileb://settings/lakes.json out --endpoint-url=http://localhost:4566
- Check the water level of the lakes throw the command
python3 getWaterLevel.py
- Receive the sms notification by invoking the other lambda function
aws lambda invoke --function-name smsNotification --payload fileb://settings/lakes.json out --endpoint-url=http://localhost:4566
Below you can see an example of execution
Caliendo Gioacchino - caliendo.gioacchino00@gmail.com
Project Link: https://github.com/Joe-cyber/LakeLevelAdvisor

