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 details)
File details
Details for the file awsjar-0.2.9.tar.gz
.
File metadata
- Download URL: awsjar-0.2.9.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c12ddc48001fe6e4c2337ece002ff986d34ec84e614d4748b10c3126ed8effc9 |
|
MD5 | 7d8e1e7a3034b530ef6cdc9675cd3221 |
|
BLAKE2b-256 | 602cdfde6d3a02625fa952fd6739d59d65374f254dc2ad2eecec2c0b30ced1ac |