Rocket Squirrel Rocket Squirrel
Rocket Squirrel

A global community of coders, developers, and designers

November 2018
M T W T F S S
« Jul    
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories


Hosting Your Service on AWS Lambda

thewongguythewongguy

Abstract

This article will go over hosting our RSS Feed Slack Bot we created earlier. If you have not followed along you can grab the code from Github. I chose to use AWS Lambda because it should cost less than a dedicated hosting solution, such as EC2. Also, I wanted to learn how to use AWS Lambda.

Adding an AWS Lambda Hook

Add this function into your bot.py file. It can be called anything, but needs to have the event and context parameters.

def lambda_handler(event, context):
    main()

Bundling Your Code

You may include your config.ini, however we will opt out and instead set up our environment variables within AWS Lambda.

zip -9 bundle.zip bot.py
zip -9r bundle.zip LICENSE
zip -9r bundle.zip README.md
zip -9r bundle.zip requirements.txt

Bundle your dependencies

cd <virtualenv directory>/lib/python3.6/site-packages
zip -9r <path to your zip>/bundle.zip *

You can view the contents of your zip by doing:

unzip -l  bundle.zip | less

Create a Role for AWS Lambda

Setting Up Your AWS Lambda

Add a Trigger

CloudWatch Logs

A new post will trigger a log like below

New Content Log

Regular non-events will have empty strings and have a lower Billed Duration

No Content Log

 

Comments 0
There are currently no comments.