lambda integration tests - test to show that environment config has an effect (#28815)

pull/30653/head
mikedlr 7 years ago committed by Ryan Brown
parent d871964aca
commit 140ea7f5ff

@ -1,5 +1,6 @@
from __future__ import print_function
import json
import os
def handler(event, context):
@ -17,7 +18,16 @@ def handler(event, context):
name = event["name"]
return {"message": "hello " + name}
# we can use environment variables as part of the configuration of the lambda
# which can change the behaviour of the lambda without needing a new upload
extra = os.environ.get("EXTRA_MESSAGE")
if extra is not None and len(extra) > 0:
greeting = "hello {0}. {1}".format(name, extra)
else:
greeting = "hello " + name
return {"message": greeting}
def main():

@ -185,12 +185,53 @@
dead_letter_arn:
register: result
- name: assert lambda was updated as expected
- name: assert lambda remains as before
assert:
that:
- 'not result|failed'
- 'result.changed == False'
# ============================================================
- name: test putting an environment variable changes lambda
lambda:
name: "{{lambda_function_name}}"
runtime: "python2.7"
handler: "mini_lambda.handler"
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}}"
environment_variables:
EXTRA_MESSAGE: "I think you are great!!"
register: result
- name: assert lambda upload succeeded
assert:
that:
- 'not result|failed'
- 'result.changed == True'
- name: test lambda works
execute_lambda:
name: "{{lambda_function_name}}"
payload:
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
- name: assert lambda manages to respond as expected
assert:
that:
- 'not result|failed'
- 'result.result.output.message == "hello Mr Ansible Tests. I think you are great!!"'
# ============================================================
- name: test state=present triggering a network exception due to bad url
lambda:

Loading…
Cancel
Save