After some tests, I figured out that my lambda function derived from the container don't work and functions created from AWS console worked.
I figured out that in my lambda function in a container the output don't in JSON format. I changed the output to JSON format and worked. Thanks On Thursday, August 25, 2022 at 8:15:30 AM UTC-4 ricardo barbosa wrote: > Hi guys, > > I'm trying to run a playbook to execute lambda, but not work. > I'm follow this > https://docs.ansible.com/ansible/latest/collections/community/aws/execute_lambda_module.html#parameter-payload > . > My playbook is > > ---------------------------------- execute-lambda.yml -------------------- > --- > # Launches a new EC2 instance > - hosts: localhost > gather_facts: false > become: false > tasks: > - name: test > community.aws.execute_lambda: > name: testelambdacontainer > payload: "{{ lookup('file','lambda_event.json') }}" > > ------------------------------------------------------------------------------------------ > > The output the execution is: > > ---------------------- execution > ---------------------------------------------------- > (ansible-venv) ricardobarbosa@demogorgon:~/ansible-test$ ansible-playbook > -vvvv execute-lambda.yml > ansible-playbook [core 2.13.2] > config file = None > configured module search path = > ['/home/ricardobarbosa/.ansible/plugins/modules', > '/usr/share/ansible/plugins/modules'] > ansible python module location = > /home/ricardobarbosa/ansible-test/ansible-venv/lib/python3.10/site-packages/ansible > ansible collection location = > /home/ricardobarbosa/.ansible/collections:/usr/share/ansible/collections > executable location = > /home/ricardobarbosa/ansible-test/ansible-venv/bin/ansible-playbook > python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] > jinja version = 3.1.2 > libyaml = True > No config file found; using defaults > setting up inventory plugins > host_list declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > Skipping due to inventory source not existing or not being readable by the > current user > script declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > auto declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > Skipping due to inventory source not existing or not being readable by the > current user > yaml declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > Skipping due to inventory source not existing or not being readable by the > current user > ini declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > Skipping due to inventory source not existing or not being readable by the > current user > toml declined parsing /etc/ansible/hosts as it did not pass its > verify_file() method > [WARNING]: No inventory was parsed, only implicit localhost is available > [WARNING]: provided hosts list is empty, only localhost is available. Note > that the implicit localhost does not match 'all' > Loading collection community.aws from > /home/ricardobarbosa/.ansible/collections/ansible_collections/community/aws > Loading callback plugin default of type stdout, v2.0 from > /home/ricardobarbosa/ansible-test/ansible-venv/lib/python3.10/site-packages/ansible/plugins/callback/default.py > Skipping callback 'default', as we already have a stdout callback. > Skipping callback 'minimal', as we already have a stdout callback. > Skipping callback 'oneline', as we already have a stdout callback. > > PLAYBOOK: execute-lambda.yml > ********************************************************************************************************************************************************************************** > Positional arguments: execute-lambda.yml > verbosity: 4 > connection: smart > timeout: 10 > become_method: sudo > tags: ('all',) > inventory: ('/etc/ansible/hosts',) > forks: 5 > 1 plays in execute-lambda.yml > > PLAY [localhost] > ********************************************************************************************************************************************************************************************** > META: ran handlers > > TASK [test] > *************************************************************************************************************************************************************************************************** > task path: /home/ricardobarbosa/ansible-test/execute-lambda.yml:7 > File lookup using /home/ricardobarbosa/ansible-test/lambda_event.json as > file > <127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ricardobarbosa > <127.0.0.1> EXEC /bin/sh -c 'echo ~ricardobarbosa && sleep 0' > <127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo > /home/ricardobarbosa/.ansible/tmp `"&& mkdir "` echo > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302 > > `" && echo ansible-tmp-1661426723.8696764-14065-204543964293302="` echo > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302 > > `" ) && sleep 0' > Loading collection amazon.aws from > /home/ricardobarbosa/.ansible/collections/ansible_collections/amazon/aws > Using module file > /home/ricardobarbosa/.ansible/collections/ansible_collections/community/aws/plugins/modules/execute_lambda.py > <127.0.0.1> PUT > /home/ricardobarbosa/.ansible/tmp/ansible-local-14061b2m1dz1y/tmpg572j460 > TO > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302/AnsiballZ_execute_lambda.py > <127.0.0.1> EXEC /bin/sh -c 'chmod u+x > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302/ > > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302/AnsiballZ_execute_lambda.py > > && sleep 0' > <127.0.0.1> EXEC /bin/sh -c > '/home/ricardobarbosa/ansible-test/ansible-venv/bin/python3 > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302/AnsiballZ_execute_lambda.py > > && sleep 0' > <127.0.0.1> EXEC /bin/sh -c 'rm -f -r > /home/ricardobarbosa/.ansible/tmp/ansible-tmp-1661426723.8696764-14065-204543964293302/ > > > /dev/null 2>&1 && sleep 0' > The full traceback is: > Traceback (most recent call last): > File > "/tmp/ansible_community.aws.execute_lambda_payload_bznt_5r5/ansible_community.aws.execute_lambda_payload.zip/ansible_collections/community/aws/plugins/modules/execute_lambda.py", > > line 243, in main > File "/usr/lib/python3.10/json/__init__.py", line 346, in loads > return _default_decoder.decode(s) > File "/usr/lib/python3.10/json/decoder.py", line 337, in decode > obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode > raise JSONDecodeError("Expecting value", s, err.value) from None > json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) > fatal: [localhost]: FAILED! => { > "boto3_version": "1.24.48", > "botocore_version": "1.27.48", > "changed": false, > "invocation": { > "module_args": { > "aws_access_key": null, > "aws_ca_bundle": null, > "aws_config": null, > "aws_secret_key": null, > "debug_botocore_endpoint_logs": false, > "dry_run": false, > "ec2_url": null, > "function_arn": null, > "name": "testelambdacontainer", > "payload": { > "BUCKET_NAME": "capsula", > "DOMAIN_NAME": "commandnotfound.com.br", > "EMAIL": "kakaroto@kakaroto" > }, > "profile": null, > "region": null, > "security_token": null, > "tail_log": false, > "validate_certs": true, > "version_qualifier": null, > "wait": true > } > }, > "msg": "Failed while decoding function return value: Expecting value: > line 1 column 1 (char 0)" > } > > PLAY RECAP > **************************************************************************************************************************************************************************************************** > localhost : ok=0 changed=0 unreachable=0 > failed=1 skipped=0 rescued=0 ignored=0 > > (ansible-venv) ricardobarbosa@demogorgon:~/ansible-test$ cat > lambda_event.json > { "DOMAIN_NAME": "commandnotfound.com.br", "EMAIL": "kakaroto@kakaroto", > "BUCKET_NAME": "capsula" } > (ansible-venv) ricardobarbosa@demogorgon:~/ansible-test$ > > ------------------------------------------------------------------------------------------- > > > Let me know where I'm wronging > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/04d3e7cd-8a22-4601-bf51-1f337a8a926bn%40googlegroups.com.
