Added missing param to lambda module to pass it through to boto3 (#58822)

* Added missing param to lambda module to pass it through to boto3

* Allow updating of runtime, because there is no reason why not

* Updated version_added to 2.10 to make tests green again

* Updated RETURN docs of Lambda module

* Added tests to aws_lambda test-suite.
pull/63804/head
Stefan Horning 5 years ago committed by Sloane Hertel
parent 92cd13a2cf
commit 7aac7a56da

@ -0,0 +1,2 @@
minor_changes:
- lambda - add a tracing_mode parameter to set the TracingConfig for AWS X-Ray. Also allow updating Lambda runtime.

@ -96,6 +96,12 @@ options:
description: description:
- The parent object that contains the target Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS topic. - The parent object that contains the target Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS topic.
version_added: "2.3" version_added: "2.3"
tracing_mode:
description:
- Set mode to 'Active' to sample and trace incoming requests with AWS X-Ray. Turned off (set to 'PassThrough') by default.
choices: ['Active', 'PassThrough']
version_added: "2.10"
tags: tags:
description: description:
- tag dict to apply to the function (requires botocore 1.5.40 or above). - tag dict to apply to the function (requires botocore 1.5.40 or above).
@ -175,7 +181,7 @@ configuration:
type: dict type: dict
sample: sample:
{ {
'code_sha256': 'SHA256 hash', 'code_sha256': 'zOAGfF5JLFuzZoSNirUtOrQp+S341IOA3BcoXXoaIaU=',
'code_size': 123, 'code_size': 123,
'description': 'My function', 'description': 'My function',
'environment': { 'environment': {
@ -188,13 +194,16 @@ configuration:
'handler': 'index.handler', 'handler': 'index.handler',
'last_modified': '2017-08-01T00:00:00.000+0000', 'last_modified': '2017-08-01T00:00:00.000+0000',
'memory_size': 128, 'memory_size': 128,
'revision_id': 'a2x9886d-d48a-4a0c-ab64-82abc005x80c',
'role': 'arn:aws:iam::123456789012:role/lambda_basic_execution', 'role': 'arn:aws:iam::123456789012:role/lambda_basic_execution',
'runtime': 'nodejs6.10', 'runtime': 'nodejs6.10',
'tracing_config': { 'mode': 'Active' },
'timeout': 3, 'timeout': 3,
'version': '1', 'version': '1',
'vpc_config': { 'vpc_config': {
'security_group_ids': [], 'security_group_ids': [],
'subnet_ids': [] 'subnet_ids': [],
'vpc_id': '123'
} }
} }
''' '''
@ -336,6 +345,7 @@ def main():
vpc_security_group_ids=dict(type='list'), vpc_security_group_ids=dict(type='list'),
environment_variables=dict(type='dict'), environment_variables=dict(type='dict'),
dead_letter_arn=dict(), dead_letter_arn=dict(),
tracing_mode=dict(choices=['Active', 'PassThrough']),
tags=dict(type='dict'), tags=dict(type='dict'),
) )
@ -370,6 +380,7 @@ def main():
vpc_security_group_ids = module.params.get('vpc_security_group_ids') vpc_security_group_ids = module.params.get('vpc_security_group_ids')
environment_variables = module.params.get('environment_variables') environment_variables = module.params.get('environment_variables')
dead_letter_arn = module.params.get('dead_letter_arn') dead_letter_arn = module.params.get('dead_letter_arn')
tracing_mode = module.params.get('tracing_mode')
tags = module.params.get('tags') tags = module.params.get('tags')
check_mode = module.check_mode check_mode = module.check_mode
@ -417,6 +428,8 @@ def main():
func_kwargs.update({'Timeout': timeout}) func_kwargs.update({'Timeout': timeout})
if memory_size and current_config['MemorySize'] != memory_size: if memory_size and current_config['MemorySize'] != memory_size:
func_kwargs.update({'MemorySize': memory_size}) func_kwargs.update({'MemorySize': memory_size})
if runtime and current_config['Runtime'] != runtime:
func_kwargs.update({'Runtime': runtime})
if (environment_variables is not None) and (current_config.get( if (environment_variables is not None) and (current_config.get(
'Environment', {}).get('Variables', {}) != environment_variables): 'Environment', {}).get('Variables', {}) != environment_variables):
func_kwargs.update({'Environment': {'Variables': environment_variables}}) func_kwargs.update({'Environment': {'Variables': environment_variables}})
@ -427,10 +440,8 @@ def main():
else: else:
if dead_letter_arn != "": if dead_letter_arn != "":
func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}}) func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}})
if tracing_mode and (current_config.get('TracingConfig', {}).get('Mode', 'PassThrough') != tracing_mode):
# Check for unsupported mutation func_kwargs.update({'TracingConfig': {'Mode': tracing_mode}})
if current_config['Runtime'] != runtime:
module.fail_json(msg='Cannot change runtime. Please recreate the function')
# If VPC configuration is desired # If VPC configuration is desired
if vpc_subnet_ids or vpc_security_group_ids: if vpc_subnet_ids or vpc_security_group_ids:
@ -555,6 +566,9 @@ def main():
if dead_letter_arn: if dead_letter_arn:
func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}}) func_kwargs.update({'DeadLetterConfig': {'TargetArn': dead_letter_arn}})
if tracing_mode:
func_kwargs.update({'TracingConfig': {'Mode': tracing_mode}})
# If VPC configuration is given # If VPC configuration is given
if vpc_subnet_ids or vpc_security_group_ids: if vpc_subnet_ids or vpc_security_group_ids:
if not vpc_subnet_ids or not vpc_security_group_ids: if not vpc_subnet_ids or not vpc_security_group_ids:

@ -1,9 +1,15 @@
--- ---
# # tasks file for aws_lambda test
# Author: Michael De La Rue
# based on ec2_key.yml + lambda.py
- block: - name: set connection information for AWS modules and run tests
module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:
# ============================================================ # ============================================================
- name: test with no parameters - name: test with no parameters
@ -20,7 +26,7 @@
# ============================================================ # ============================================================
- name: test with no parameters except state absent - name: test with no parameters except state absent
lambda: lambda:
state=absent state: absent
register: result register: result
ignore_errors: true ignore_errors: true
@ -33,8 +39,8 @@
# ============================================================ # ============================================================
- name: test with no role or handler - name: test with no role or handler
lambda: lambda:
name=ansible-testing-fake-should-not-be-created name: ansible-testing-fake-should-not-be-created
runtime="python2.7" runtime: "python2.7"
register: result register: result
ignore_errors: true ignore_errors: true
@ -47,10 +53,11 @@
# ============================================================ # ============================================================
- name: test with all module required variables but no region - name: test with all module required variables but no region
lambda: lambda:
name=ansible-testing-fake-should-not-be-created name: ansible-testing-fake-should-not-be-created
runtime="python2.7" runtime: "python2.7"
handler="no-handler" handler: "no-handler"
role=arn:fake-role-doesnt-exist role: "arn:fake-role-doesnt-exist"
region:
register: result register: result
ignore_errors: true ignore_errors: true
@ -76,6 +83,7 @@
vpc_security_group_ids: vpc_security_group_ids:
environment_variables: environment_variables:
dead_letter_arn: dead_letter_arn:
region:
register: result register: result
ignore_errors: true ignore_errors: true
@ -101,31 +109,24 @@
- name: test state=present - upload the lambda - name: test state=present - upload the lambda
lambda: lambda:
name="{{lambda_function_name}}" name: "{{lambda_function_name}}"
runtime="python2.7" runtime: "python2.7"
handler="mini_lambda.handler" handler: "mini_lambda.handler"
role="ansible_lambda_role" role: "ansible_lambda_role"
ec2_region='{{ec2_region}}' zip_file: "{{zip_res.dest}}"
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
zip_file="{{zip_res.dest}}"
register: result register: result
- name: assert lambda upload succeeded - name: assert lambda upload succeeded
assert: assert:
that: that:
- 'result is not failed' - result is not failed
- result.configuration.tracing_config.mode == "PassThrough"
- name: test lambda works - name: test lambda works
execute_lambda: execute_lambda:
name: "{{lambda_function_name}}" name: "{{lambda_function_name}}"
payload: payload:
name: "Mr Ansible Tests" name: "Mr Ansible Tests"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result register: result
- name: assert lambda manages to respond as expected - name: assert lambda manages to respond as expected
@ -134,16 +135,63 @@
- 'result is not failed' - 'result is not failed'
- 'result.result.output.message == "hello Mr Ansible Tests"' - 'result.result.output.message == "hello Mr Ansible Tests"'
- name: test lambda config updates
lambda:
name: "{{lambda_function_name}}"
runtime: "nodejs10.x"
tracing_mode: 'Active'
handler: "mini_lambda.handler"
role: "ansible_lambda_role"
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is not failed
- update_result.changed == True
- update_result.configuration.runtime == 'nodejs10.x'
- update_result.configuration.tracing_config.mode == 'Active'
- name: test no changes are made with the same parameters
lambda:
name: "{{lambda_function_name}}"
runtime: "nodejs10.x"
tracing_mode: 'Active'
handler: "mini_lambda.handler"
role: "ansible_lambda_role"
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is not failed
- update_result.changed == False
- update_result.configuration.runtime == 'nodejs10.x'
- update_result.configuration.tracing_config.mode == 'Active'
- name: reset config updates for the following tests
lambda:
name: "{{lambda_function_name}}"
runtime: "python2.7"
tracing_mode: 'PassThrough'
handler: "mini_lambda.handler"
role: "ansible_lambda_role"
register: result
- name: assert that reset succeeded
assert:
that:
- result is not failed
- result.changed == True
- result.configuration.runtime == 'python2.7'
- result.configuration.tracing_config.mode == 'PassThrough'
# ============================================================ # ============================================================
- name: test state=present with security group but no vpc - name: test state=present with security group but no vpc
lambda: lambda:
name: "{{lambda_function_name}}" name: "{{lambda_function_name}}"
runtime: "python2.7" runtime: "python2.7"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
handler: handler:
description: description:
@ -168,10 +216,6 @@
name: "{{lambda_function_name}}" name: "{{lambda_function_name}}"
runtime: "python2.7" runtime: "python2.7"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
# These are not allowed because of mutually exclusive. # These are not allowed because of mutually exclusive.
@ -191,8 +235,6 @@
- 'result is not failed' - 'result is not failed'
- 'result.changed == False' - 'result.changed == False'
# ============================================================ # ============================================================
- name: test putting an environment variable changes lambda - name: test putting an environment variable changes lambda
lambda: lambda:
@ -200,10 +242,6 @@
runtime: "python2.7" runtime: "python2.7"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
environment_variables: environment_variables:
EXTRA_MESSAGE: "I think you are great!!" EXTRA_MESSAGE: "I think you are great!!"
@ -220,9 +258,6 @@
name: "{{lambda_function_name}}" name: "{{lambda_function_name}}"
payload: payload:
name: "Mr Ansible Tests" name: "Mr Ansible Tests"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}' security_token: '{{security_token}}'
register: result register: result
@ -256,12 +291,8 @@
# ============================================================ # ============================================================
- name: test state=absent (expect changed=False) - name: test state=absent (expect changed=False)
lambda: lambda:
name="{{lambda_function_name}}" name: "{{lambda_function_name}}"
ec2_region='{{ec2_region}}' state: absent
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=absent
register: result register: result
- name: assert state=absent - name: assert state=absent
@ -279,10 +310,6 @@
runtime: "python2.7" runtime: "python2.7"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_1 register: async_1
@ -293,10 +320,6 @@
runtime: "python2.7" runtime: "python2.7"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_2 register: async_2
@ -307,10 +330,6 @@
runtime: "python2.7" runtime: "python2.7"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_3 register: async_3
@ -321,10 +340,6 @@
runtime: "python2.7" runtime: "python2.7"
handler: "mini_lambda.handler" handler: "mini_lambda.handler"
role: "ansible_lambda_role" role: "ansible_lambda_role"
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
register: result register: result
@ -356,10 +371,6 @@
lambda: lambda:
name: "{{lambda_function_name}}_1" name: "{{lambda_function_name}}_1"
state: absent state: absent
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_1 register: async_1
@ -368,10 +379,6 @@
lambda: lambda:
name: "{{lambda_function_name}}_2" name: "{{lambda_function_name}}_2"
state: absent state: absent
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_2 register: async_2
@ -380,10 +387,6 @@
lambda: lambda:
name: "{{lambda_function_name}}_3" name: "{{lambda_function_name}}_3"
state: absent state: absent
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
async: 1000 async: 1000
register: async_3 register: async_3
@ -392,10 +395,6 @@
lambda: lambda:
name: "{{lambda_function_name}}_4" name: "{{lambda_function_name}}_4"
state: absent state: absent
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
zip_file: "{{zip_res.dest}}" zip_file: "{{zip_res.dest}}"
register: result register: result
@ -422,29 +421,11 @@
until: job_result is finished until: job_result is finished
retries: 30 retries: 30
# ============================================================
# ============================================================
# upload via s3 bucket - multi function
# ============================================================
# update already existing function
always: always:
# ============================================================ - name: ensure function is absent at end of test
- name: test state=absent (expect changed=False)
lambda: lambda:
name="{{lambda_function_name}}" name: "{{lambda_function_name}}"
ec2_region='{{ec2_region}}' state: absent
ec2_access_key='{{ec2_access_key}}' ignore_errors: true
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=absent
register: result
- name: assert state=absent
assert:
that:
- 'result is not failed'
- 'result.changed == False'

Loading…
Cancel
Save