mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 07:01:22 -07:00
[aws] Enable SQS events for lambda_event
module (#43019)
* Enable SQS events for `lambda_event` module * Handle SQS event type properly * PEP8
This commit is contained in:
parent
fdf51f2a43
commit
b6f8de9204
1 changed files with 17 additions and 6 deletions
|
@ -47,10 +47,12 @@ options:
|
||||||
required: false
|
required: false
|
||||||
event_source:
|
event_source:
|
||||||
description:
|
description:
|
||||||
- Source of the event that triggers the lambda function.
|
- Source of the event that triggers the lambda function.
|
||||||
|
- For DynamoDB and Kinesis events, select 'stream'
|
||||||
|
- For SQS queues, select 'sqs'
|
||||||
required: false
|
required: false
|
||||||
default: stream
|
default: stream
|
||||||
choices: ['stream']
|
choices: ['stream', 'sqs']
|
||||||
source_params:
|
source_params:
|
||||||
description:
|
description:
|
||||||
- Sub-parameters required for event source.
|
- Sub-parameters required for event source.
|
||||||
|
@ -61,6 +63,11 @@ options:
|
||||||
time of invoking your function. Default is 100.
|
time of invoking your function. Default is 100.
|
||||||
- C(starting_position) The position in the stream where AWS Lambda should start reading.
|
- C(starting_position) The position in the stream where AWS Lambda should start reading.
|
||||||
Choices are TRIM_HORIZON or LATEST.
|
Choices are TRIM_HORIZON or LATEST.
|
||||||
|
- I(== sqs event source ==)
|
||||||
|
- C(source_arn) The Amazon Resource Name (ARN) of the SQS queue to read events from.
|
||||||
|
- C(enabled) Indicates whether AWS Lambda should begin reading from the event source. Default is True.
|
||||||
|
- C(batch_size) The largest number of records that AWS Lambda will retrieve from your event source at the
|
||||||
|
time of invoking your function. Default is 100.
|
||||||
required: true
|
required: true
|
||||||
requirements:
|
requirements:
|
||||||
- boto3
|
- boto3
|
||||||
|
@ -321,6 +328,9 @@ def lambda_event_stream(module, aws):
|
||||||
starting_position = source_params.get('starting_position')
|
starting_position = source_params.get('starting_position')
|
||||||
if starting_position:
|
if starting_position:
|
||||||
api_params.update(StartingPosition=starting_position)
|
api_params.update(StartingPosition=starting_position)
|
||||||
|
elif module.params.get('event_source') == 'sqs':
|
||||||
|
# starting position is not required for SQS
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Source parameter 'starting_position' is required for stream event notification.")
|
module.fail_json(msg="Source parameter 'starting_position' is required for stream event notification.")
|
||||||
|
|
||||||
|
@ -384,7 +394,7 @@ def lambda_event_stream(module, aws):
|
||||||
def main():
|
def main():
|
||||||
"""Produce a list of function suffixes which handle lambda events."""
|
"""Produce a list of function suffixes which handle lambda events."""
|
||||||
this_module = sys.modules[__name__]
|
this_module = sys.modules[__name__]
|
||||||
source_choices = ["stream"]
|
source_choices = ["stream", "sqs"]
|
||||||
|
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
|
@ -413,9 +423,10 @@ def main():
|
||||||
|
|
||||||
validate_params(module, aws)
|
validate_params(module, aws)
|
||||||
|
|
||||||
this_module_function = getattr(this_module, 'lambda_event_{0}'.format(module.params['event_source'].lower()))
|
if module.params['event_source'].lower() in ('stream', 'sqs'):
|
||||||
|
results = lambda_event_stream(module, aws)
|
||||||
results = this_module_function(module, aws)
|
else:
|
||||||
|
module.fail_json('Please select `stream` or `sqs` as the event type')
|
||||||
|
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue