Last active
May 28, 2019 03:05
-
-
Save doi-t/565ecdd600a4acbad5c2fc14517a00bb to your computer and use it in GitHub Desktop.
Simple example of envattrs for aws lambda function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# echo '{}' > event.json; mkdir -p libs; pip install attrs envattrs -t libs; \ | |
# export YOUR_PREFIX_SLACK_CHANNEL=your_project-staging; \ | |
# export YOUR_PREFIX_S3_BUCKET=pyconapac-bucket; \ | |
# export YOUR_PREFIX_THRESHOLD=50; \ | |
# python-lambda-local -l libs/ -f handler -t 5 lambda_pyconapac.py event.json | |
from typing import Dict | |
import attr | |
import envattrs | |
@attr.s | |
class LambdaConfig: | |
slack_channel = attr.ib(convert=str) | |
s3_bucket = attr.ib(convert=str) | |
threshold = attr.ib(convert=int) | |
def handler(event: Dict, context: Dict): | |
lambda_config = envattrs.load(LambdaConfig, 'YOUR_PREFIX') | |
print(f"{lambda_config.__dict__}") | |
print(f">>> LambdaConfig.slack_channel: {LambdaConfig.slack_channel}") | |
print(f">>> LambdaConfig.s3_bucket: {LambdaConfig.s3_bucket}") | |
print(f">>> LambdaConfig.threshold: {LambdaConfig.threshold}") | |
return lambda_config.__dict__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment