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

Adding environment variable support for lambda.py in response to feat… #20705

Merged
merged 3 commits into from
Feb 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/ansible/modules/cloud/amazon/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
- List of VPC security group IDs to associate with the Lambda function. Required when vpc_subnet_ids is used.
required: false
default: None
environment_variables:
description:
- A dictionary of environment variables the Lambda function is given.
required: false
default: None
aliases: [ 'environment' ]
author:
- 'Steyn Huizinga (@steynovich)'
extends_documentation_fragment:
Expand All @@ -120,11 +126,18 @@
vpc_security_group_ids:
- sg-123abcde
- sg-edcba321
environment_variables: '{{ item.env_vars }}'
with_items:
- name: HelloWorld
zip_file: hello-code.zip
env_vars:
key1: "first"
key2: "second"
- name: ByeBye
zip_file: bye-code.zip
env_vars:
key1: "1"
key2: "2"

# Basic Lambda function deletion
tasks:
Expand Down Expand Up @@ -221,6 +234,7 @@ def main():
memory_size=dict(type='int', default=128),
vpc_subnet_ids=dict(type='list', default=None),
vpc_security_group_ids=dict(type='list', default=None),
environment_variables=dict(type='dict', default=None),
)
)

Expand Down Expand Up @@ -250,6 +264,7 @@ def main():
memory_size = module.params.get('memory_size')
vpc_subnet_ids = module.params.get('vpc_subnet_ids')
vpc_security_group_ids = module.params.get('vpc_security_group_ids')
environment_variables = module.params.get('environment_variables')

check_mode = module.check_mode
changed = False
Expand Down Expand Up @@ -306,6 +321,8 @@ def main():
func_kwargs.update({'Timeout': timeout})
if memory_size and current_config['MemorySize'] != memory_size:
func_kwargs.update({'MemorySize': memory_size})
if (environment_variables is not None) and (current_config['Environment']['Variables'] != environment_variables):
func_kwargs.update({'Environment':{'Variables': environment_variables}})

# Check for unsupported mutation
if current_config['Runtime'] != runtime:
Expand Down Expand Up @@ -338,7 +355,7 @@ def main():
func_kwargs.update({'VpcConfig':{'SubnetIds': [], 'SecurityGroupIds': []}})

# Upload new configuration if configuration has changed
if len(func_kwargs) > 2:
if len(func_kwargs) > 1:
try:
if not check_mode:
response = client.update_function_configuration(**func_kwargs)
Expand Down Expand Up @@ -421,6 +438,7 @@ def main():
'Code': code,
'Timeout': timeout,
'MemorySize': memory_size,
'Environment':{'Variables': environment_variables}
}

# If VPC configuration is given
Expand Down