Jar make it easy to store the state of your AWS Lambda functions.
Project description
AWS Jar
AWSJar makes it easy to save data from AWS Lambda.
The data (either a dict or list) can be saved within the Lambda itself as an environment variable or on S3.
Install
pip install awsjar
Examples
Increment a sum with every invocation
import awsjar
def lambda_handler(event, context):
jar = awsjar.Jar(context.function_name)
data = jar.get() # Will return an empty dict if state does not already exist.
s = data.get("sum", 0)
data["sum"] = s + 1
jar.put(data)
return data
Make sure your website is up 24/7
import awsjar
import requests
# Set a CloudWatch Event to run this Lambda every minute.
def lambda_handler(event, context):
jar = awsjar.Jar(context.function_name)
data = jar.get() # Will return an empty dict if state does not already exist.
last_status_code = data.get("last_status_code", 200)
result = requests.get('http://example.com')
cur_status_code = result.status_code
if last_status_code != 200 and cur_status_code != 200:
print('Website might be down!')
jar.put({'last_status_code': cur_status_code})
Save data to S3
import awsjar
# Save your data to an S3 object - s3://my-bucket/state.json
bkt = awsjar.Bucket('my-bucket', key='state.json')
data = {'num_acorns': 50, 'acorn_hideouts': ['tree', 'lake', 'backyard']}
bkt.put(data)
state = bkt.get()
>> {'num_acorns': 50, 'acorn_hideouts': ['tree', 'lake', 'backyard']}
Docs
Contributing
Please see the contributing guide for more specifics.
Contact / Support
Please use the Issues page
I greatly appreciate any feedback / suggestions! Email me at: yukisawa@gmail.com
License
Distributed under the Apache License 2.0. See LICENSE
for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
awsjar-0.2.9.tar.gz
(22.2 kB
view hashes)