Skip to content

ChristophShyper/lambda-airly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

lambda-airly

Description

AWS Lambda function/application invoking Airly API to get some basic information about current air quality.

Lambda code is writen in Python 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: Email notification example

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. SMS notification example

TODO list

  • Add unit tests for Python code
  • Add Lambda functional testing with lambci/docker-lambda
  • Create Terraform module from the current setup + add tags
  • Add simple scripts for single deployment. Use 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

Terraform disclaimer

Infrastructure part can be easily deployed with Terraform 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.

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.

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

Releases

No releases published

Packages

No packages published