@ -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'