SLaT
Simple Lambda Toolkit
Collection of reusable Python tools for lambda development.
This project is meant to :meat_on_bone: (or :corn:) these requirements
- As a lambda developer I want to write as little boilerplate as possible
- As a lambda developer I want to ensure I produce high value, discoverable logs
- As a lambda developer I want to ensure I sends proper, consistent, well formed responses
- As a lambda developer I want ToBeDetermined
Example hello world Lambda
from slat.log_util import LogUtil
from slat.response import LambdaProxyResponse
from slat.types import JsonapiBody
# initiate you logger outside the handler
log = LogUtil.init_logger(env_var_name='LOG_LEVEL', default_level='INFO')
def lambda_handler(event, context):
# bind the request id to the logger
LogUtil.init_request({'request_id': context.aws_request_id})
# make log statements as normal
log.debug('Lambda Handler Event', lambda_handler_event=event)
# prepare a Jsonapi payload (https://jsonapi.org/)
response_body = JsonapiBody(data={'hello': 'world!'}, errors=[], meta={})
# respond in the expected APIGateway lambda proxy format (https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format)
return LambdaProxyResponse.respond(200, response_body, context)
Slat Tools
Responses
TBDocumented
Logging
Structlog is used for structured JSON logging
Example Usage
import logging
from slat.log_util import LogUtil
log = LogUtil.init_logger(default_level='INFO', correlation_id_key_val={'request_id': '999'})
log.info('is this JSON: {"answer": 42}')
log.error("the log message", some="value", extra_data=[1, 2, 3, "4"])
# only OUR logger will render as JSON
logging.getLogger("test").warning("hello")
output:
{"event": "is this JSON: {\"answer\": 42}", "level": "info", "logger": "slat.log_util", "request_id": "999", "timestamp": "2019-11-06T21:04:33.517295Z"}
{"event": "the log message", "extra_data": [1, 2, 3, "4"], "level": "error", "logger": "slat.log_util", "request_id": "999", "some": "value", "timestamp": "2019-11-06T21:04:33.517652Z"}
hello
For test runs you can add an ENV flag TESTING_RUN=true and log statements will be written to ./testing.log
TESTING_RUN=true pytest
Running tests
pytest
# with coverage
pytest --cov=slat
# generage html report
coverage html
open ./htmlcov/index.html
Developing
create file ~/.pypirc
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository: https://upload.pypi.org/legacy/
username:
password:
[pypitest]
repository: https://test.pypi.org/legacy/
username:
password:
build
# tick to semver `version` in setup.py
rm -rf dist
python setup.py bdist_wheel --universal
pypitest
twine upload --repository pypitest dist/*
pip install slat --index-url https://test.pypi.org/simple/ --upgrade
pypi
twine upload --repository pypi dist/*
pip install slat --upgrade
Metadata
Release files for slat 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slat-0.3.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / slat-0.3.1-py2.py3-none-any.whl
| Download URL | slat-0.3.1-py2.py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
01c2f39dfdd8017746920276435afb2ea99e616ae4ad6a2b621d89c895647bb5
|
|
BLAKE2b-256 checksum How to use checksums |
1d844df83e3c26ec53d5cf78419a9be7cdba81fc098769cb0101a4de6178c04d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4
|
Security for slat 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.