https://github.com/umihico/stateful-lambda-layer
python layer.zip to make lambda stateful by rewriting environment variables
https://github.com/umihico/stateful-lambda-layer
Last synced: 7 months ago
JSON representation
python layer.zip to make lambda stateful by rewriting environment variables
- Host: GitHub
- URL: https://github.com/umihico/stateful-lambda-layer
- Owner: umihico
- Created: 2019-12-25T06:34:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-26T04:43:23.000Z (almost 6 years ago)
- Last Synced: 2025-01-15T23:15:54.582Z (9 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Stateful-Lambda-Layer
Complete updating and managing environment variables in AWS Lambda by itself!If your API keys or something which expire regularly, you don't have to store the small data somewhere outside.
**This is not a best practice. You should use AWS System Manager Parameter Store if you need to update the env too often.**
## Installation
1. Download [python-layer.zip](https://github.com/umihico/stateful-lambda-layer/raw/master/python-layer.zip)
1. Add python-layer.zip as one of lambda layers and attach it on your lambda function.
1. Attach policy `AWSLambdaFullAccess` or something on your lambda role to let boto3 executes `boto3.client('lambda').update_function_configuration`## Usage
```python
from lambdaenv import LambdaEnv
def lambda_handler(event, context):
old_val=os.getenv('example_key') # "old_data"
lambdaenv=LambdaEnv(context)
lambdaenv.set('example_key', "new_data")
new_val=lambdaenv.get('example_key') # lambdaenv.get is equivalent to os.getenv
```if you execute this lambda again or see the configuration, you see the environment variables are changed!
## Contributing
I would be happy if somebody supply the same function with other languages.