Quickly and easily create AWS lambda python functions and make them available from a url.
$ pip install herd
Create a python file:
$ touch foo.py
and then edit foo.py
to add a lambda function:
# foo.py
import json
def handler(event, context):
"""This is the description of the lambda function that will show up in AWS console"""
return {
'statusCode': 200,
'body': json.dumps({'query_string': event["queryStringParameters"]}),
}
You should set a few environment variables:
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_DEFAULT_REGION="us-west-1"
$ herd function-add foo.py
Function foo available at url: https://XXXXXXXXXXX.execute-api.us-west-1.amazonaws.com/herd-lambda-api/foo
$ curl "https://XXXXXXXXXXX.execute-api.us-west-1.amazonaws.com/herd-lambda-api/foo?foo=1&bar=2"
{"query_string": {"foo": "1", "bar": "2"}}
That's it!
You can pass in environment variables that your lambda function would have access to by defining them on the command line:
$ herd function-add foo.py --ENV_NAME_1=value1 --ENV_NAME_2=value2
Herd is still in an alpha state and as we start using it for some of our infrastructure I'm sure it will change here and there. We also have more functionality planned for it in the future.