I\'m getting the error \"The role defined for the function cannot be assumed by Lambda\" when I\'m trying to create a lambda function with create-function command.
Had the same issue although my IAM role did have the right policy and trust relationship. Lambda creation worked fine when done through CLI the problem was when using lambda module after just creating the IAM role.
I also tried to "pause" for few seconds but it didn't help.
Ended up adding retry and delay until registerdLambda.code was defined. Usually it works after 1-2 tries.
example:
- name: creating lambda function
lambda:
state: present
name: "{{ lambdaName }}"
zip_file: "{{ lambdaZipFile }}"
runtime: "{{ lambdaRuntime }}"
role: "{{ lambdaRole }}"
description: "{{ lambdaDescription }}"
handler: "{{ lambdaHandler }}"
register: lambdaFunc
retries: 3
delay: 10
until: "{{ lambdaFunc.code is defined }}"