Repository: ansible-collections/amazon.aws

Issue:
lambda_execute doesn't work with function_arn instead of name
### Summary

The documentation says that I can use either `name` or `function_arn` for `execute_lambda`. This is not the case currently, because only the `name` (possibly `None`) is passed to the waiter.

I found the line of code in my local installation of this module that's causing the issue.

```
wait_for_lambda(client, module, name)
```

Changing it to:

```
wait_for_lambda(client, module, name or function_arn)
```

fixes the issue.

But I can't see that line [here](https://github.com/ansible-collections/community.aws/blob/1a1be5f494bb3935084b33d9183a41b9e9389cff/plugins/modules/execute_lambda.py) in the git repo.
It's not just that this bug has been possibly fixed, but that the whole function waiting for the lambda to be updated is missing from the latest commit.
Was this functionality removed? (That would be surprising.)

[The docs](https://docs.ansible.com/ansible/latest/collections/community/aws/execute_lambda_module.html) say `version 3.6.0`, which is what I'm using.

### Issue Type

Bug Report

### Component Name

execute_lambda

### Ansible Version

```console (paste below)
$ ansible --version  -e ansible_python_interpreter=$(which python3)                                                                                                                    
ansible [core 2.13.6]
  config file = /home/ec2-user/.ansible.cfg
  configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ec2-user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ec2-user/.pyenv/versions/3.8.11/bin/ansible
  python version = 3.8.11 (default, Sep  7 2022, 04:17:12) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]
  jinja version = 3.1.2
  libyaml = True
```


### Collection Versions

```console (paste below)
# /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    3.5.0  
ansible.netcommon             3.1.3  
ansible.posix                 1.4.0  
ansible.utils                 2.7.0  
ansible.windows               1.12.0 
arista.eos                    5.0.1  
awx.awx                       21.8.0 
azure.azcollection            1.14.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.3.1  
cisco.aci                     2.3.0  
cisco.asa                     3.1.0  
cisco.dnac                    6.6.0  
cisco.intersight              1.0.20 
cisco.ios                     3.3.2  
cisco.iosxr                   3.3.1  
cisco.ise                     2.5.8  
cisco.meraki                  2.11.0 
cisco.mso                     2.1.0  
cisco.nso                     1.0.3  
cisco.nxos                    3.2.0  
cisco.ucs                     1.8.0  
cloud.common                  2.1.2  
cloudscale_ch.cloud           2.2.2  
community.aws                 3.6.0  
community.azure               1.1.0  
community.ciscosmb            1.0.5  
community.crypto              2.8.1  
community.digitalocean        1.22.0 
community.dns                 2.4.0  
community.docker              2.7.1  
community.fortios             1.0.0  
community.general             5.8.0  
community.google              1.0.0  
community.grafana             1.5.3  
community.hashi_vault         3.4.0  
community.hrobot              1.6.0  
community.libvirt             1.2.0  
community.mongodb             1.4.2  
community.mysql               3.5.1  
community.network             4.0.1  
community.okd                 2.2.0  
community.postgresql          2.3.0  
community.proxysql            1.4.0  
community.rabbitmq            1.2.3  
community.routeros            2.3.1  
community.sap                 1.0.0  
community.sap_libs            1.3.0  
community.skydive             1.0.0  
community.sops                1.4.1  
community.vmware              2.10.1 
community.windows             1.11.1 
community.zabbix              1.8.0  
containers.podman             1.9.4  
cyberark.conjur               1.2.0  
cyberark.pas                  1.0.14 
dellemc.enterprise_sonic      1.1.2  
dellemc.openmanage            5.5.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.20.0 
fortinet.fortimanager         2.1.6  
fortinet.fortios              2.1.7  
frr.frr                       2.0.0  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.8.2  
hpe.nimble                    1.1.4  
ibm.qradar                    2.1.0  
ibm.spectrum_virtualize       1.10.0 
infinidat.infinibox           1.3.7  
infoblox.nios_modules         1.4.0  
inspur.ispim                  1.2.0  
inspur.sm                     2.3.0  
junipernetworks.junos         3.1.0  
kubernetes.core               2.3.2  
lowlydba.sqlserver            1.0.4  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.21.0
netapp.elementsw              21.7.0 
netapp.ontap                  21.24.1
netapp.storagegrid            21.11.1
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.3.1  
netbox.netbox                 3.8.1  
ngine_io.cloudstack           2.2.4  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.2  
openstack.cloud               1.10.0 
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   2.3.1  
purestorage.flasharray        1.14.0 
purestorage.flashblade        1.10.0 
purestorage.fusion            1.1.1  
sensu.sensu_go                1.13.1 
servicenow.servicenow         1.0.6  
splunk.es                     2.1.0  
t_systems_mms.icinga_director 1.31.4 
theforeman.foreman            3.7.0  
vmware.vmware_rest            2.2.0  
vultr.cloud                   1.3.0  
vyos.vyos                     3.0.1  
wti.remote                    1.0.4  
```


### AWS SDK versions

```console (paste below)
$ pip show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.24.82
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages
Requires: jmespath, botocore, s3transfer
Required-by: credstash, aws-sam-translator, redshift-connector, moto, awswrangler
---
Name: botocore
Version: 1.27.82
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages
Requires: jmespath, urllib3, python-dateutil
Required-by: s3transfer, aws-xray-sdk, redshift-connector, moto, boto3, awswrangler
╭╴~/environment/repo/MWE (srcclr_docker)
╰ $ pip3 show boto boto3 botocore                                                                                                                                                        
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.24.82
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages
Requires: jmespath, botocore, s3transfer
Required-by: credstash, aws-sam-translator, redshift-connector, moto, awswrangler
---
Name: botocore
Version: 1.27.82
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /home/ec2-user/.pyenv/versions/3.8.11/lib/python3.8/site-packages
Requires: jmespath, urllib3, python-dateutil
Required-by: s3transfer, aws-xray-sdk, redshift-connector, moto, boto3, awswrangler
```

(Unsure how meaningful this is because I specify the interpreter on each run with `-e ansible_python_interpreter=$(which python3)`)

### Configuration

```console (paste below)
$ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/home/ec2-user/.ansible.cfg) = True
DEFAULT_LOCAL_TMP(/home/ec2-user/.ansible.cfg) = /dev/shm/ansible/tmp_local/ansible-local-14524dud79jcc
DEFAULT_STDOUT_CALLBACK(/home/ec2-user/.ansible.cfg) = yaml
INTERPRETER_PYTHON(/home/ec2-user/.ansible.cfg) = /usr/bin/python3
```


### OS / Environment

Amazon Linux 2

### Steps to Reproduce

Create a Lambda function named `mylambda`. Update the `vars` for your AWS account.

```yaml
---
- hosts: localhost
  connection: local
  vars:
    lambda_name: mylambda
    account_number: 1234
    region: ap-southeast-2
  tasks:
  - name: with name
    community.aws.execute_lambda:
      name: "{{ lambda_name }}"
  - name: with ARN as name
    community.aws.execute_lambda:
      name: "arn:aws:lambda:{{ region }}:{{ account_number }}:function:{{ lambda_name }}"
  - name: with ARN as ARN
    community.aws.execute_lambda:
      function_arn: "arn:aws:lambda:{{ region }}:{{ account_number }}:function:{{ lambda_name }}"
```


### Expected Results

The lambda is invoked 3 times.

### Actual Results

```
PLAY [localhost] ************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [with name] ************************************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [with ARN as name] *****************************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [with ARN as ARN] ******************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Invalid type for parameter FunctionName, value: None, type: <class 'NoneType'>, valid types: <class 'str'>
fatal: [127.0.0.1]: FAILED! => changed=false 
  boto3_version: 1.24.82
  botocore_version: 1.27.82
  msg: |-
    Failed while waiting on lambda to be Active: Parameter validation failed:
    Invalid type for parameter FunctionName, value: None, type: <class 'NoneType'>, valid types: <class 'str'>

PLAY RECAP ******************************************************************************************************************************************************************************
127.0.0.1                  : ok=3    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Note that passing the ARN into the name field does seem to work. Even though the docs say not to do it.
Hi @mdavis-xyz,

Thanks for taking the time to open this issue, the module was actually moved to the amazon.aws collection with release 5.0.0 (the ansible.com "latest" docs are tied to the latest version of **Ansible** rather than the collection)

The best place to look for the 'latest' version of the community.aws and amazon.aws collections is Ansible Galaxy: https://galaxy.ansible.com/amazon/aws and https://galaxy.ansible.com/community/aws, with the docs being available on github.io https://ansible-collections.github.io/amazon.aws/branch/stable-5/collections/amazon/aws/index.html https://ansible-collections.github.io/community.aws/branch/stable-5/collections/community/aws/index.html

It looks like waiter is still there:
https://github.com/ansible-collections/amazon.aws/blob/8ea102260d7d98a5f9eb9f0856b01901db198707/plugins/modules/lambda_execute.py#L268 and I suspect the bug will still be there too.

The module's been renamed from execute_lambda to lambda_execute, as part of a mass-rename in 5.0.0 to try and make our module names more consistent and (hopefully) make modules easier to find in the medium/long term.

Resolving patch:
diff --git a/plugins/modules/lambda_execute.py b/plugins/modules/lambda_execute.py
--- a/plugins/modules/lambda_execute.py
+++ b/plugins/modules/lambda_execute.py
@@ -212,7 +212,7 @@ def main():
         module.exit_json(changed=True)
 
     try:
-        wait_for_lambda(client, module, name)
+        wait_for_lambda(client, module, name or function_arn)
         response = client.invoke(**invoke_params, aws_retry=True)
     except is_boto3_error_code('ResourceNotFoundException') as nfe:
         module.fail_json_aws(nfe, msg="Could not find Lambda to execute. Make sure "
@@ -265,12 +265,12 @@ def main():
     module.exit_json(changed=True, result=results)
 
 
-def wait_for_lambda(client, module, name):
+def wait_for_lambda(client, module, name_or_arn):
     try:
         client_active_waiter = client.get_waiter('function_active')
         client_updated_waiter = client.get_waiter('function_updated')
-        client_active_waiter.wait(FunctionName=name)
-        client_updated_waiter.wait(FunctionName=name)
+        client_active_waiter.wait(FunctionName=name_or_arn)
+        client_updated_waiter.wait(FunctionName=name_or_arn)
     except botocore.exceptions.WaiterError as e:
         module.fail_json_aws(e, msg='Timeout while waiting on lambda to be Active')
     except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:


Test patch:
diff --git a/tests/integration/targets/lambda/tasks/main.yml b/tests/integration/targets/lambda/tasks/main.yml
--- a/tests/integration/targets/lambda/tasks/main.yml
+++ b/tests/integration/targets/lambda/tasks/main.yml
@@ -184,6 +184,10 @@
       - result.configuration.tracing_config.mode == "PassThrough"
       - result.configuration.architectures == ['arm64']
 
+  - name: Save Lambda ARN
+    ansible.builtin.set_fact:
+      lambda_function_arn: "{{ result['configuration']['function_arn'] }}"
+
   - include_tasks: tagging.yml
 
   # Test basic operation of Uploaded lambda
@@ -212,6 +216,18 @@
       - result is not failed
       - result.result.output.message == "hello Mr Ansible Tests"
 
+  - name: test execute lambda with function arn
+    lambda_execute:
+      function_arn: "{{ lambda_function_arn }}"
+      payload:
+        name: Mr Ansible Tests
+    register: result
+  - name: assert lambda manages to respond as expected
+    assert:
+      that:
+      - result is not failed
+      - result.result.output.message == "hello Mr Ansible Tests"
+
   # Test updating Lambda
   - name: test lambda config updates (check mode)
     lambda:
@@ -644,7 +660,7 @@
     assert:
       that:
       - result is not failed
-  
+
   # Test creation with layers
   - name: Create temporary directory for testing
     tempfile: