Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If you need to deploy a new package outside of Travis then do the following, *no
Configuration
^^^^^^^^^^^^^

In order for the Lambda to run, carbon needs a few environment variables set.
In order for the Lambda to run, carbon needs a few environment variables set. These can either be set in the environment or passed to the Lambda function through the event JSON object. Variables set using the event object will overwrite those set in the environment.

+-----------+-------------------------------------------------------------+
| Variable | Description |
Expand Down
6 changes: 4 additions & 2 deletions carbon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
'VISITING SENIOR LECTURER', 'PART-TIME FLEXIBLE/LL',
)

ENV_VARS = ('FTP_USER', 'FTP_PASS', 'FTP_PATH', 'FTP_HOST', 'FTP_PORT',
'CARBON_DB')


def people():
"""A person generator.
Expand Down Expand Up @@ -301,8 +304,7 @@ class Config(dict):
@classmethod
def from_env(cls):
cfg = cls()
for var in ['FTP_USER', 'FTP_PASS', 'FTP_PATH', 'FTP_HOST',
'CARBON_DB', ]:
for var in ENV_VARS:
cfg[var] = os.environ.get(var)
return cfg

Expand Down
3 changes: 2 additions & 1 deletion lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import boto3

from carbon.app import Config, FTPFeeder
from carbon.app import Config, ENV_VARS, FTPFeeder
from carbon.db import engine


Expand All @@ -12,6 +12,7 @@ def handler(event, context):
secret = client.get_secret_value(SecretId=os.environ['SECRET_ID'])
secret_env = json.loads(secret['SecretString'])
cfg = Config.from_env()
cfg.update({k: event[k] for k in ENV_VARS if k in event})
cfg.update(secret_env)
engine.configure(cfg['CARBON_DB'])
FTPFeeder(event, context, cfg).run()