Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awslambda put_function_env functionality #82

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
17 changes: 16 additions & 1 deletion chaosaws/awslambda/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,33 @@ def put_function_memory_size(function_name: str, memory_size: int,
memory_size=memory_size)


def put_function_env(function_name: str, env: Dict[str, str],
configuration: Configuration = None,
secrets: Secrets = None) -> AWSResponse:
"""
Sets environment variables for the function.
"""
client = aws_client("lambda", configuration, secrets)
return _update_function_configuration(function_name=function_name,
client=client,
env=env)


###############################################################################
# Private functions
###############################################################################
def _update_function_configuration(function_name: str,
client: boto3.client,
timeout: int = None,
memory_size: int = None) -> AWSResponse:
memory_size: int = None,
env: Dict[str, str] = None) -> AWSResponse:
request_kwargs = {
'FunctionName': function_name
}
if timeout is not None:
request_kwargs['Timeout'] = timeout
if memory_size is not None:
request_kwargs['MemorySize'] = memory_size
if env is not None:
request_kwargs['Environment'] = {'Variables': env}
return client.update_function_configuration(**request_kwargs)
15 changes: 14 additions & 1 deletion tests/awslambda/test_awslambda_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
invoke_function,
put_function_concurrency,
put_function_memory_size,
put_function_timeout)
put_function_timeout,
put_function_env)


@patch('chaosaws.awslambda.actions.aws_client', autospec=True)
Expand Down Expand Up @@ -166,3 +167,15 @@ def test_aws_lambda_put_function_memory_size(aws_client):
client.update_function_configuration.assert_called_with(
FunctionName=lambda_function_name,
MemorySize=memory_size)


@patch('chaosaws.awslambda.actions.aws_client', autospec=True)
def test_aws_lambda_put_function_env(aws_client):
client = MagicMock()
aws_client.return_value = client
lambda_function_name = 'my-lambda-function'
env = {'Testing': 'true'}
put_function_env(lambda_function_name, env)
client.update_function_configuration.assert_called_with(
FunctionName=lambda_function_name,
Environment={'Variables': env})