You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lambda_execute should cope with list as payload (instead of dict)Â #1082
---
- hosts: localhost
connection: local
vars:
payload:
- abc
- 123
arn: "arn:aws:lambda:ap-southeast-2:123:function:empty" # TODO: change for your case
region: "ap-southeast-2"
tasks:
- name: invoke using cli
shell: >
aws lambda invoke
--function-name {{ arn }}
--invocation-type RequestResponse
--payload '{{ payload | to_json }}'
/tmp/result
- name: through Ansible module
execute_lambda:
function_arn: "{{ arn }}"
region: "{{ region }}"
wait: yes
tail_log: yes
payload: "{{ payload }}"
Where arn is the arn of a Lambda with body:
def lambda_handler(event, context):
return event
This example invokes the Lambda from the cli (which works),
then tries to do the same thing from execute_lambda, which doesn't work.
EXPECTED RESULTS
The playbook should run without error
ACTUAL RESULTS
TASK [through Ansible module] **********************************************************************************************************************
custom filter file loaded
fatal: [localhost]: FAILED! => {"changed": false, "msg": "argument payload is of type <class 'list'> and we were unable to convert to dict: <class 'list'> cannot be converted to a dict"}
I'm happy to write this PR myself (change that line, add an integration test, update documentation), as soon as someone answers issue ansible-collections/community.aws#120 .
Adding a new key really doesn't seem like the best solution. In theory Ansible modules can take in any arbitrary json. So it should be possible.
I've dug deeper. Here's the list of standard Ansible types..
I suspect that json would work. (Noting that it would end up in the module as a string, not a list/dict. Which is fine because we have to dump the payload to json anyway.) raw would probably work too.
Looking at this comment I'm leaning more towards json instead of raw. json` will do validation to ensure that the payload can be dumped to json, which is a requirement for this use case, right?
What type validation do we have to do for raw, other than checking that it can be dumped with json.dumps?
I'm trying to think about the edge case where someone might want to invoke a Lambda with a payload that is just a string, i.e. json.dumps("{"). Oh well, I guess we can check that with the tests.
changed the title [-]execute_lambda should cope with list as payload (instead of dict)[/-][+]lambda_execute should cope with list as payload (instead of dict)[/+]on Sep 28, 2022
Activity
mdavis-xyz commentedon Jun 27, 2020
I can't see where the problem is.
Line 218 should take a list fine. Same with line 173.
I think the solution is as simple as modifying line 154, where the argument spec is, to allow dicts and lists.
I'm happy to write this PR myself (change that line, add an integration test, update documentation), as soon as someone answers issue ansible-collections/community.aws#120 .
Tagging maintainer: @ryansb
mdavis-xyz commentedon Jun 30, 2020
Hmm, it looks like you can tell Ansible that an argument is a dict, or a list, but you can't tell it to accept either.
Is that correct?
https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html#documentation-fields
mdavis-xyz commentedon Jun 30, 2020
I suppose one workaround would be to add a second argument. So you do either
payload: {}orpayload_list: []. But that's not ideal.ansibullbot commentedon Aug 19, 2020
cc @jillr @s-hertel @tremble @wimnat
click here for bot help
goneri commentedon Feb 3, 2021
Hi @mdavis-xyz,
I'm not totally sure if we need a new key for that but since you've already done 80% of the job, I suggest you to push a PR for review.
mdavis-xyz commentedon Feb 3, 2021
Adding a new key really doesn't seem like the best solution. In theory Ansible modules can take in any arbitrary json. So it should be possible.
I've dug deeper. Here's the list of standard Ansible types..
I suspect that
jsonwould work. (Noting that it would end up in the module as a string, not a list/dict. Which is fine because we have to dump the payload to json anyway.)rawwould probably work too.Which is better:
raworjson?If neither works, it looks like we can even pass in a callable to do the conversion ourselves.
mdavis-xyz commentedon Feb 3, 2021
This issue has a related example
goneri commentedon Feb 4, 2021
I would go with
raw(e.g: https://github.com/openstack/ansible-collections-openstack/blob/master/plugins/modules/server.py#L493) and do a type validation after.mdavis-xyz commentedon Feb 4, 2021
Looking at this comment I'm leaning more towards
jsoninstead ofraw.json` will do validation to ensure that the payload can be dumped to json, which is a requirement for this use case, right?What type validation do we have to do for
raw, other than checking that it can be dumped withjson.dumps?I'm trying to think about the edge case where someone might want to invoke a Lambda with a payload that is just a string, i.e.
json.dumps("{"). Oh well, I guess we can check that with the tests.Add integration tests for ec2.connect_to_aws and ec2.ec2_connect (#123)
[-]execute_lambda should cope with list as payload (instead of dict)[/-][+]lambda_execute should cope with list as payload (instead of dict)[/+]ci(deps): bump the github-actions group with 2 updates (#3173)