diff --git a/lib/ansible/modules/cloud/amazon/lambda.py b/lib/ansible/modules/cloud/amazon/lambda.py index 78f761d7eb..d42999e009 100644 --- a/lib/ansible/modules/cloud/amazon/lambda.py +++ b/lib/ansible/modules/cloud/amazon/lambda.py @@ -96,6 +96,12 @@ options: - 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: @@ -120,11 +126,18 @@ tasks: 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: @@ -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), ) ) @@ -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 @@ -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: @@ -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) @@ -421,6 +438,7 @@ def main(): 'Code': code, 'Timeout': timeout, 'MemorySize': memory_size, + 'Environment':{'Variables': environment_variables} } # If VPC configuration is given