Skip to content

Commit

Permalink
lambda_execute: allow function arn instead of name (#1275)
Browse files Browse the repository at this point in the history
lambda_execute: allow function arn instead of name

SUMMARY
Fixes #1268
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
lambda_execute
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
  • Loading branch information
mdavis-xyz authored Nov 18, 2022
1 parent 58d9471 commit 00d3317
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1268-lambda-execute-arn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- lambda_execute - Fix waiter error when ``function_arn`` is passed instead of ``name``(https://github.com/ansible-collections/amazon.aws/issues/1268).
8 changes: 4 additions & 4 deletions plugins/modules/lambda_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/targets/lambda/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -644,7 +660,7 @@
assert:
that:
- result is not failed

# Test creation with layers
- name: Create temporary directory for testing
tempfile:
Expand Down

0 comments on commit 00d3317

Please sign in to comment.