Repository: ansible/ansible

Issue:
Add support for DeadLetterConfig
##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
lambda module

##### ANSIBLE VERSION
N/A

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
lambda module does not currently support setting or retrieving the DeadLetterConfig setting on lambda functions.

##### STEPS TO REPRODUCE

```yaml
# Create Lambda functions
tasks:
- name: looped creation
  lambda:
    name: '{{ item.name }}'
    state: present
    zip_file: '{{ item.zip_file }}'
    runtime: 'python2.7'
    role: 'arn:aws:iam::987654321012:role/lambda_basic_execution'
    dead_letter_config_arn: "{{ item.dead_letter_config_arn | default(omit) }}"
    handler: 'hello_python.my_handler'
    vpc_subnet_ids:
    - subnet-123abcde
    - subnet-edcba321
    vpc_security_group_ids:
    - sg-123abcde
    - sg-edcba321
  with_items:
    - { name: HelloWorld, zip_file: 'hello-code.zip' }
    - { name: ByeBye, zip_file: 'bye-code.zip' }
    - name: NotSoFast
       zip_file: 'nsf-code.zip'
       dead_letter_config_arn: value      
```

##### EXPECTED RESULTS
The function has its DeadLetterConfig:TargetArn set to value in an idempotent fashion.

##### ACTUAL RESULTS
The support for this in the current module is not present.



Discussion:
cc @steynovich
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/lambda.py b/lib/ansible/modules/cloud/amazon/lambda.py
--- a/lib/ansible/modules/cloud/amazon/lambda.py
+++ b/lib/ansible/modules/cloud/amazon/lambda.py
@@ -103,6 +103,12 @@
     default: None
     aliases: [ 'environment' ]
     version_added: "2.3"
+  dead_letter_arn:
+    description:
+      - The parent object that contains the target Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS topic.
+    required: false
+    default: None
+    version_added: "2.3"
 author:
     - 'Steyn Huizinga (@steynovich)'
 extends_documentation_fragment:
@@ -236,6 +242,7 @@ def main():
         vpc_subnet_ids=dict(type='list', default=None),
         vpc_security_group_ids=dict(type='list', default=None),
         environment_variables=dict(type='dict', default=None),
+        dead_letter_arn=dict(type='str', default=None),
         )
     )
 
@@ -266,6 +273,7 @@ def main():
     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')
+    dead_letter_arn = module.params.get('dead_letter_arn')
 
     check_mode = module.check_mode
     changed = False
@@ -324,6 +332,13 @@ def main():
             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}})
+        if dead_letter_arn is not None:
+            if current_config.get('DeadLetterConfig'):
+                if current_config['DeadLetterConfig']['TargetArn'] != dead_letter_arn:
+                    func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}})
+            else:
+                if dead_letter_arn != "":
+                    func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}})
 
         # Check for unsupported mutation
         if current_config['Runtime'] != runtime:
@@ -442,6 +457,9 @@ def main():
                        'Environment':{'Variables': environment_variables}
                        }
 
+        if dead_letter_arn:
+            func_kwargs.update({'DeadLetterConfig': {'TargetARN': dead_letter_arn}})
+
         # If VPC configuration is given
         if vpc_subnet_ids or vpc_security_group_ids:
             if len(vpc_subnet_ids) < 1:


Test patch: