An open API service indexing awesome lists of open source software.

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

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.