Provides a bunch of functions and utils to help you build applications on top of Amazon Web Services Resources
Project description
Fluxo AWS
Provides a bunch of functions and utils to help you build applications on top of Amazon Web Services Resources. We use this in our web development flow and would love hear suggestions and improvements on this.
Usage
Just import the function or class that you want to use, and you're good to go
Functions
AWS Lambda handlers
prepare_response
Function Decorator that:
- Allows you to make a response in a tuple format containing
(status_code, body, headers)
. Example:return 200, {"success": True}
- If body is
dict
orlist
, runsjson.dumps
function with encoders fordatetime.datetime
,decimal.Decimal
andbytes
- Add CORS headers
- Add JSON content type header
- Defaults your response: 200 for status code,
{}
for body
Usage:
from fluxo_aws import prepare_response
@prepare_response
def handler(event, context):
return 200, {"success": True}
event_parser
Function decorator that transform your event variable to a ParsedEvent
class, exposing three methods: body
, headers
and query
. It will transform strings
into dict
, and parse variables for you.
Usage
from fluxo_aws import prepare_response, event_parser
@prepare_response
@event_parser
def handler(event, context):
print(event.body)
print(event.headers)
print(event.query)
param = event.query.get("param")
return 200
DynamoDB handlers
DynamodbTable(table_name, schema, hash_key=None, partition_key=None)
Helper for DynamoDB. schema is a valid cerberus schema dict. This class exposes:
exists(id, hash_key=None)
: check if hash key exists in table, returningTrue
ofFalse
get_by_hash_key(id, hash_key=None)
: get a list of records for given hash keyadd(data)
: insert dict into DynamoDB. RaiseSchemaError
if dict does not match schema with table schema
Usage
from fluxo_aws import DynamodbTable, SchemaError
schema = {"name": {"type": "string"}}
table = DynamodbTable("table", schema, hash_key=name)
try:
table.add({"name": 123})
except SchemaError as e:
print(f"schema error: {str(e)}")
print(table.exists("test"))
print(table.get_by_hash_key("test"))
Auth handlers
hash_password(password)
Hashes and salt a password string using bcrypt
and HS256
Usage
from fluxo_aws import hash_password
print(hash_password("secret"))
verify_password(plain_password, hashed_password)
Compares a hash string with a password string, returning True
if matches and False
if not matches
Usage
from fluxo_aws import verify_password
print(verify_password("secret", "..."))
create_access_token(data, expires_delta, secret_key)
Creates a JSON Web Token for data with an expiration delta of expires_delta
Usage
from fluxo_aws import create_access_token
from uuid import uuid4
from datetime import timedelta
print(create_access_token({"test": True}, timedelta(hours=3), str(uuid4())))
decode_token(data, secret_key)
WIP
S3 handlers
S3Bucket(bucket_name)
Helper for S3 Operations. This class exposes:
upload_file(file_name, object_name=None)
: upload local file to S3 returnsTrue
if uploaded successfully elseFalse
download_file(object_name, file_name=None)
: download S3 file locallycreate_presigned_url(object_name, action="get_object", expiration=3600)
: creates a presigned URL for S3 object. Returns presigned URL if successfully else returns None
Usage
from fluxo_aws import S3Bucket
s3_bucket = S3Bucket("my-test-bucket")
object_name = "test_file.txt"
file_name = "/tmp/text_file.txt"
print(s3_bucket.upload_file(file_name, object_name))
print(s3_bucket.create_presigned_url(object_name, action, expiration))
print(s3_bucket.download_file(object_name, file_name))
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
Built Distribution
File details
Details for the file fluxo-aws-0.0.13.tar.gz
.
File metadata
- Download URL: fluxo-aws-0.0.13.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf5a2eefa772b6b73afc2f0d1c40e5bb665e71ee965bbb3754d0c7283125bac8 |
|
MD5 | 76eed14e47148f36857eae911179a9e3 |
|
BLAKE2b-256 | 523c1878abfd123520cc0011a6f79c0b2be3edaf7463a5a50641091c37d127ba |
File details
Details for the file fluxo_aws-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: fluxo_aws-0.0.13-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e91a48d8e4cffd482ab9c23f229be0607331119bf620d22f8b7b69d3492e714c |
|
MD5 | 5687aceffae7563c8206d37561602b64 |
|
BLAKE2b-256 | fd98dbfffa5d99e37d20a8691ba15e6a93cb161792e9759eedb90a3582099596 |