Skip to content

Commit

Permalink
Merge branch 'stage-independent-lambda-function-config'
Browse files Browse the repository at this point in the history
PR #1162

* stage-independent-lambda-function-config:
  Add changelog for #1162
  Add docs for stage independent lambda functions
  allow for stage-independent lambda function config
  • Loading branch information
jamesls committed Aug 8, 2019
2 parents baba518 + df8d38b commit 1cfae93
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 12 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
CHANGELOG
=========

Next Release (TBD)
==================

* Add support for stage independent lambda configuration
(#1162 <https://github.com/aws/chalice/pull/1162>`__)


1.10.0
======

* Add experimental support for websockets
(`#1017 <https://github.com/aws/chalice/issues/1017>`__)
* API Gateway Endpoint Type Configuration
(`#1160 https://github.com/aws/chalice/pull/1160`__)
(`#1160 <https://github.com/aws/chalice/pull/1160>`__)
* API Gateway Resource Policy Configuration
(`#1160 https://github.com/aws/chalice/pull/1160`__)
(`#1160 <https://github.com/aws/chalice/pull/1160>`__)
* Add --merge-template option to package command
(`#1195 https://github.com/aws/chalice/pull/1195`__)
(`#1195 <https://github.com/aws/chalice/pull/1195>`__)
* Add support for packaging via terraform
(`#1129 https://github.com/aws/chalice/pull/1129`__)
(`#1129 <https://github.com/aws/chalice/pull/1129>`__)


1.9.1
Expand Down
15 changes: 11 additions & 4 deletions chalice/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,22 @@ def _chain_lookup(self, name, varies_per_chalice_stage=False,
varies_per_function=False):
# type: (str, bool, bool) -> Any
search_dicts = [self._user_provided_params]
if varies_per_function:
if varies_per_chalice_stage:
search_dicts.append(
self._config_from_disk.get('stages', {}).get(
self.chalice_stage, {}))
if varies_per_function:
# search order:
# config['stages']['lambda_functions']
# config['stages']
# config['lambda_functions']
search_dicts.insert(
0, self._config_from_disk.get('stages', {}).get(
self.chalice_stage, {}).get('lambda_functions', {}).get(
self.function_name, {}))
if varies_per_chalice_stage:
search_dicts.append(
self._config_from_disk.get('stages', {}).get(
self.chalice_stage, {}))
self._config_from_disk.get('lambda_functions', {}).get(
self.function_name, {}))
search_dicts.extend([self._config_from_disk, self._default_params])
for cfg_dict in search_dicts:
if isinstance(cfg_dict, dict) and cfg_dict.get(name) is not None:
Expand Down
24 changes: 21 additions & 3 deletions docs/source/topics/configfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ Lambda Specific Configuration

In addition to a chalice stage, there are also some configuration values
that can be specified per Lambda function. A chalice app can have many
stages, and a stage can have many Lambda functions. To configure
per lambda configuration, you add a ``lambda_functions`` key in your
stage configuration::
stages, and a stage can have many Lambda functions.

You have the option to specify configuration for a lambda function across
all your stages, or for a lambda function in a specific stage.

To configure per lambda configuration for a specific stage, you add a
``lambda_functions`` key in your stage configuration::

{
"version": "2.0",
Expand All @@ -228,6 +232,20 @@ stage configuration::
}
}

To specify per lambda configuration across all stages, you add
a top level ``lambda_functions`` key::

{
"version": "2.0",
"app_name": "app",
"lambda_functions": {
"foo": {
"lamba_timeout": 120
}
}
}


Each key in the ``lambda_functions`` dictionary is the name of a Lambda
function in your app. The value is a dictionary of configuration that
will be applied to that function. These are the configuration options
Expand Down
40 changes: 39 additions & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,60 @@ def test_can_chain_chalice_stage_values():
def test_can_chain_function_values():
disk_config = {
'lambda_timeout': 10,
'lambda_functions': {
'api_handler': {
'lambda_timeout': 15,
}
},
'stages': {
'dev': {
'lambda_timeout': 20,
'lambda_functions': {
'api_handler': {
'lambda_timeout': 30,
}
}
}
}
}
}
c = Config(chalice_stage='dev',
config_from_disk=disk_config)
assert c.lambda_timeout == 30


def test_can_set_stage_independent_function_values():
disk_config = {
'lambda_timeout': 10,
'lambda_functions': {
'api_handler': {
'lambda_timeout': 15,
}
}
}
c = Config(chalice_stage='dev',
config_from_disk=disk_config)
assert c.lambda_timeout == 15


def test_stage_overrides_function_values():
disk_config = {
'lambda_timeout': 10,
'lambda_functions': {
'api_handler': {
'lambda_timeout': 15,
}
},
'stages': {
'dev': {
'lambda_timeout': 20,
}
}
}
c = Config(chalice_stage='dev',
config_from_disk=disk_config)
assert c.lambda_timeout == 20


def test_can_create_scope_obj_with_new_function():
disk_config = {
'lambda_timeout': 10,
Expand Down

0 comments on commit 1cfae93

Please sign in to comment.