A simple session manager for aws lambda function using dynamodb
Project description
Session Lambda
A simple way to manage sessions for AWS Lambdas
Install
pip install session-lambda
Example
Set SESSION_LAMBDA_DYNAMODB_TABLE_NAME
env var:
export SESSION_LAMBDA_DYNAMODB_TABLE_NAME=<table-name>
Run the following python code:
from session_lambda import session, set_session_data, get_session_data
@session
def lambda_handler(event, context):
session_data = get_session_data()
# core_logic(event, context, session_data)
set_session_data(data="hello world")
return {"session_data_before": session_data, "session_data_after": get_session_data()}
print(lambda_handler({'headers':{"session-id": "0"}}, {}))
print(lambda_handler({'headers':{"session-id": "0"}}, {}))
print(lambda_handler({'headers':{"session-id": "1"}}, {}))
You should get the following prints:
{'session_data_before': None, 'session_data_after': 'hello world'}
{'session_data_before': 'hello world', 'session_data_after': 'hello world'}
{'session_data_before': None, 'session_data_after': 'hello world'}
Features
@session(id_key_name='session-id', return_session_id_in_header=True, update=False)
def lambda_handler(event, context):
...
id_key_name
is the expected key name in theevent[headers]
. It is default tosession-id
. It is case-sensitive.update
flag let you decide weather to update the session data each call or just not. It is default toFalse
.return_session_id_in_header
flag lets you control is thesession-id
is added to the response's headers (ifheaders
exists in response). It is default toTrue
.
Future Features
- Support TTL
- Support Schema validation for session data
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
session_lambda-0.1.1.tar.gz
(4.2 kB
view details)
Built Distribution
File details
Details for the file session_lambda-0.1.1.tar.gz
.
File metadata
- Download URL: session_lambda-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.5 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b522382d99d6dbce6a0c10d1be684e70d3bb9d71ad36162b37f01ff556e86ef6 |
|
MD5 | 3903de13993dc0e7abc6984457241c27 |
|
BLAKE2b-256 | b9f6f2fd5148308ab87786649c2eb5e085e4f931f55c193c795a8751e13f46d6 |
Provenance
File details
Details for the file session_lambda-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: session_lambda-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.9.5 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f88ce5e8de01864fea715dea1119e2000862fb748f3d2dc4d749752507f8cc1 |
|
MD5 | 23b179d16c143a89ed99f4419cb776c5 |
|
BLAKE2b-256 | 96ff4c1a06ca73fea54dffd3aaba71e3d9365788417270cfbd2be11483127c61 |