This code monitors Chicago's Open Data Portal for new inspections at your favorite restaurant. It runs on AWS and posts the results to Slack.
Here's how we'll do it:
- Query the Food Inspections dataset once a day.
- If an inspection record exists for your favorite restaurant, post a short summary and a link to the complete record to Slack.
Slack has a Python package, but you have to jump through a bunch of hoops to install it
for Lambda. We'll use the requests
module (available from botocore.vendored
) to
post with webhooks. Slack's documentation
explains how to set it up. You'll need the URL Slack gives you.
- Choose
create function
. - Choose
author from scratch
. - Provide a name, choose
Python 3.6
,create new role from templates
, name it, and then attachBasic Edge Lambda permissions
andKMS decryption permissions
. - Add
Cloudwatch Events
to the left and, if it's not there,Amazon Cloudwatch Logs
to the right. - Click on
Cloudwatch Events
and scroll down. - Choose
create new rule
. Paste your cron expression inschedule expression
. To run the query every day at noon GMT, entercron(00 12 ? * * *)
. - Click on the box with the function name.
- Paste
inspection_function.py
into the code box. - Define three environment variables:
SLACK_URL
: the URL Slack created for you when you created the webhook.CHANNEL
: the Slack channel where you want your messages to appear, e.g.#general
.AKA_NAME
: The beginning of your favorite restaurant's AKA name. For Sun Wah it's%20%27SUN%20WAH%27
.