Codename: Applesauce Week One (aka Tweeting w/ Lambda)

First week of progress. Started small and have continuously added/improved. At this point I have a Lambda function in Python that takes the input of action and project then append the time (hard-coded to be EST). I think I need to simplify back to the original thought of just doing start and stop time, though other input is good for testing (see here).

Without further ado, here’s the progress made so far.

I started out with this simple tutorial on getting set up to tweet via a Python script. In a relatively shot period of time I was able to do my first tweet through a Python script. Good first step! Next step was to have it run as a Lambda function. I initially found this repository that looked promising. I really liked the idea of a KMS key and the ability to have the credentials encrypted. I started going down the route of integrating KMS. I created a new key, and found some good info here.

That all worked as expected… Lets try it all in a Lambda now! Trying to get all the dependancies good. Check here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

Not coming from a Python background, but wanting to learn more, I was getting stuck with the zip file creation. Having a single script run was fine, but certain imports, dependencies, and config files would require a zip. This site helped out with a basic bash script to create that.

I modified both the bash script and lambda_function.py to do my bidding. The twitter credentials are in clear text which is a no-no, but fine for testing, however next step is to get them encrypted using KMS. As for now, though, here is what I have on the bash script side:

This was all working well, but I then wanted to update directly from terminal rather than using the management console every time, so I added the AWSLambdaFullAccess policy to my project IAM user, and executed the following:

The biggest issue I ran into was forgetting to base64 encode the encrypted credentials which made Python cry. I added this and all worked as expected. As of now I am just storing these in a file that gets read on the lambda function. I’ll have to do something better with this in the future.

All in all, a successful first week. Forcing myself to use Python over bash has been fulfilling. As for where to go next… I would like to start storing data in DynamoDB, but will hold off on that until I am done with the course I am currently taking on A Cloud Curu.

That being the case, I’ll likely try to create an Alexa skill so that I can trigger this function by talking to my Alexas. More to come on that over the next week!