https://github.com/christophshyper/lambda-airly
AWS Lambda function/application invoking Airly API to get some basic information about current air quality
https://github.com/christophshyper/lambda-airly
airly airly-api api-client aws-lambda lambda-architecture lambda-functions serverless serverless-applications terraform terraform-aws
Last synced: 9 months ago
JSON representation
AWS Lambda function/application invoking Airly API to get some basic information about current air quality
- Host: GitHub
- URL: https://github.com/christophshyper/lambda-airly
- Owner: ChristophShyper
- License: gpl-3.0
- Created: 2019-11-20T20:56:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-08T07:29:44.000Z (over 1 year ago)
- Last Synced: 2025-03-17T04:07:04.971Z (9 months ago)
- Topics: airly, airly-api, api-client, aws-lambda, lambda-architecture, lambda-functions, serverless, serverless-applications, terraform, terraform-aws
- Language: HCL
- Homepage:
- Size: 134 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lambda-airly
# Description
[AWS](https://aws.amazon.com/) [Lambda](https://aws.amazon.com/lambda/) function/application invoking [Airly](https://airly.eu/) [API](https://developer.airly.eu/) to get some basic information about current [air quality](https://www.airqualitynow.eu/pollution_home.php).
Lambda code is writen in [Python](https://www.python.org/) and is rather easy to understand. As it only calls API and filters the result.
## Email notification
Full information about at all indexes, pollutants and weather conditions.
Example of email received when there is bad air quality at location named Home:

## SMS notification
Only basic information, about main index value, percentage of pollutants indexes, and weather conditions.
Example of SMS received when there is good air quality at location named Home.

# TODO list
* Add unit tests for Python code
* Add Lambda functional testing with [lambci/docker-lambda](https://github.com/lambci/docker-lambda)
* Create Terraform module from the current setup + add tags
* Add simple scripts for single deployment.
Use [Krzysztof-Szyper-Epam/docker-terragrunt](https://github.com/Krzysztof-Szyper-Epam/docker-terragrunt), so the only prerequisite will be Docker.
* Add DynamoDB table for location lists. Allow different combinations of location, trigger and topic.
# Prerequisites
- [AWS](https://aws.amazon.com/) account, free tier should be enough to run it.
- [Airly devloper](https://developer.airly.eu/) account with [API key](https://developer.airly.eu/docs#general.authentication)
- [Python](https://www.python.org/) and [Terraform](https://www.terraform.io/) basics
- [Linux](https://www.linux.org/) or [WSL](https://docs.microsoft.com/pl-pl/windows/wsl/install-win10) for running deployment scripts and tasks
- [Docker](https://www.docker.com/) host application to run the deployment (for building Python requirements)
# Terraform disclaimer
Infrastructure part can be easily deployed with [Terraform](https://www.terraform.io/) with already existing definition.
It's meant be just an example of implementation, hence S3 bucket used for Lambda package will be created and destroy by default.
For simplicity Terraform backend is set be local only, so don't run it in a container or untrusted host, because you may loose or expose your tfstate file.
To adjust it to your existing infrastructure some Terraform basic knowledge is necessary.
# AWS credentials
Follow instruction in [AWS documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).
# Configuration
Create `secrets.tfvars` file and put there your values as in example below.
For more details see description of those variables in `variables.tf`.
Example shows value that you *NEED* to set, other values can be overwritten if you like.
```hcl-terraform
airly_api_key = "1234567890abcdefABCDEF1234567890"
enable_bucket_creation = true
enable_bucket_termination = true
user_email = "" # can be empty - email notification will not be sent
user_locations = [{
expression = "cron(0 11 ? * * *)" # trumpet call played at 12:00 each day - https://en.wikipedia.org/wiki/St._Mary%27s_Trumpet_Call
map_point = "https://airly.eu/map/en/#50.06170,19.93734" # location of Krakow Cloth Hall - https://en.wikipedia.org/wiki/Krak%C3%B3w_Cloth_Hall
name = "Sukiennice" # name of this place in Polish
}]
user_phone = "" # can be empty - text notification will not be sent
s3_bucket = "my-bucket" # must be provided
s3_key = "" # can be empty - default location will be created
```
# Test
# Deploy
- `cd terraform`
- `terraform init`
- `terraform apply -var-file=secrets.tfvars`