
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
A simple way to manage sessions for AWS Lambdas
This package simplfy the way one can use DynamoDB as a key/value presistance layer for AWS Lambda - using a single python decorator.
pip install session-lambda
key
of type stringttl
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):
print(get_session_data())
set_session_data((get_session_data() or 0)+1)
return {"headers":{}}
# first client_a call
response = lambda_handler({'headers':{}}, {})
# get session id from response (created by the server)
session_id = response.get('headers').get('session-id')
# use session id in subsequent calls
lambda_handler({'headers':{'session-id':session_id}}, {})
lambda_handler({'headers':{'session-id':session_id}}, {})
lambda_handler({'headers':{'session-id':session_id}}, {})
# first client_b call
lambda_handler({'headers':{}}, {})
You should get the following prints:
None
1
1
1
None
This time using the update=True
mode:
from session_lambda import session, set_session_data, get_session_data
@session(update=True)
def lambda_handler(event, context):
print(get_session_data())
set_session_data((get_session_data() or 0)+1)
return {"headers":{}}
# first client_a call
response = lambda_handler({'headers':{}}, {})
# get session id from response (created by the server)
session_id = response.get('headers').get('session-id')
# use session id in subsequent calls
lambda_handler({'headers':{'session-id':session_id}}, {})
lambda_handler({'headers':{'session-id':session_id}}, {})
lambda_handler({'headers':{'session-id':session_id}}, {})
# first client_b call
lambda_handler({'headers':{}}, {})
Now you should see:
None
1
2
3
None
@session(id_key_name='session-id', update=False, ttl=0)
def lambda_handler(event, context):
...
id_key_name
is the expected key name in the event[headers]
. It is default to session-id
. It is case-sensitive.update
flag control weather set_sessions_data
updates the data. It is default to False
.ttl
is seconds interval for the session to live (since the last update time). By default it is disabled. Any value larger then 0 will enable this feature. Make sure to set the TTL key name in your dynamodb to ttl
.Check this session-lambda-example
repository for more usage examples:
https://github.com/roy-pstr/session-lambda-example
Check this medium post for general guidance: https://medium.com/@roy-pstr/a-simple-way-to-manage-sessions-with-aws-lambda-dynamodb-in-python-c7aae1aa7258
FAQs
A simple session manager for aws lambda function using dynamodb
We found that session-lambda demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.