aws-lambda-configurer

aws-lambda-configurer - Resolve AWS lambda configuration from description field and other sources (e.g. s3)


Licenses
Apache-2.0/libpng-2.0
Install
pip install aws-lambda-configurer==0.1.1

Documentation

Build Status Coverage Status

aws-lambda-configurer

This package allows to configure an AWS lambda function by JSON specified in the description of the lambda function. The python function aws_lambda_configurer.load_config is passed the lambda-function context argument The result is a dictionary read from the JSON configuration.

Basic usage

Set the description of your Lambda function to some valid JSON like

{"foo":"bar"}

You can retrieve this data in your lambda function with

from aws_lambda_configurer import load_config

def handler(event, context):
  my_config = load_config(Context=context)

The my_config variable is now set to the dictionary defined by the JSON.

External configurations

Since the lambda-description is limited to 256 chars, this module supports resolving the config from external locations. To enable this, the configuration may contain a field _lookup which allows to define those lookups. Any external configuration will be merged with the default one and the _lookup field gets removed.

S3

Configuration in S3 in bucket my-bucket as file my-config.json

{
  "hello": 123,
  "override": "2"
}

Set the description of your lambda to

{  
  "_lookup" : {
    "s3": {
      "bucket": "my-bucket",
      "key": "my-config.json"
    }
  }, 
  "foo": "bar",
  "override": "1"
}

The final configuration will be

{
  "hello": 123,
  "foo": "bar", 
  "override": "2"
}

Notice that the override variable in the final config is "2", not "1". Values in the S3 bucket take precedence over those in the lambda function's description.

Todo

  • Support more lookup types

License

Copyright 2015 Immobilien Scout GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at::

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.