https://github.com/trustcruit/tclambda
AWS Lambda calling library
https://github.com/trustcruit/tclambda
aws-lambda python3 python37
Last synced: 3 months ago
JSON representation
AWS Lambda calling library
- Host: GitHub
- URL: https://github.com/trustcruit/tclambda
- Owner: trustcruit
- License: mit
- Created: 2019-04-30T07:04:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T03:13:31.000Z (over 3 years ago)
- Last Synced: 2025-09-29T19:40:11.149Z (6 months ago)
- Topics: aws-lambda, python3, python37
- Language: Python
- Homepage: https://pypi.org/project/tclambda/
- Size: 143 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**DO NOT USE, THIS IS PRE-ALPHA, ~HAS NO TESTS~, NO MONITORING, BAD LOGGING**
# tclambda
AWS Lambda calling library
Works together with functions defined in [tc-sam-cli](https://pypi.org/project/tc-sam-cli/)
## Configuration of AWS Lambda
```python
# app.py
import tclambda
from numpy.polynomial.polynomial import polyfit as np_polyfit
handler = tclambda.LambdaHandler()
@handler.register()
def polyfit(*args, **kwargs):
return list(np_polyfit(*args, **kwargs))
```
The registered handler must return something that is json serializable.
## Usage in other projects
Configuration is primarely done by environmental variables.
```sh
TC_NUMPY_QUEUE="https://sqs.eu-west-1.amazonaws.com/12345/NumpySqs"
TC_NUMPY_BUCKET="s3-result-bucket"
```
```python
from tclambda.auto_functions import numpy
lambda_result = numpy.polyfit([1, 2], [2, 1], 1)
print(lambda_result.result())
# Output: [2.999999999999998, -0.9999999999999992]
```
## Retry lambda
```python
import tclambda
import requests
handler = tclambda.LambdaHandler()
@handler.register()
def web_data(*args, **kwargs):
try:
response = requests.get("https://example.com")
response.raise_for_status()
except Exception as e:
raise tclambda.RetryException(e)
return response.text
```
## Error handling
### Sentry
Install tclambda together with sentry `pip install tclambda[sentry]`
Setting up sentry is done automatically through environmental variables.
- SENTRY_DSN
- SENTRY_RELEASE
- SENTRY_ENVIRONMENT
# Tests
- Create an S3 bucket to test live against
- Add `TC_THIS_BUCKET=my-test-s3-bucket` to `.env`
- Run `pipenv run test`