Skip to content

Commit

Permalink
increase sqs message visibility timeout (#19125) (#19141)
Browse files Browse the repository at this point in the history
* increase sqs message visibility timeout and chunk the creation of incidents

* add release notes and increment version

Co-authored-by: Jason Rauen <rauen_jason@bah.com>
  • Loading branch information
content-bot and badarsebard authored May 23, 2022
1 parent 1798897 commit 5848e08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 11 additions & 9 deletions Packs/AWS-SQS/Integrations/AWS-SQS/AWS-SQS.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,20 @@ def parse_incident_from_finding(message, parse_body_as_json=False):
def fetch_incidents(aws_client, aws_queue_url, max_fetch, parse_body_as_json):
try:
client = aws_client.aws_session(service='sqs')
receipt_handles = [] # type: list
incidents = [] # type: list
incidents_created = 0 # type: int
max_number_of_messages = min(max_fetch, 10)
while len(incidents) < max_fetch:
while incidents_created < max_fetch:
receipt_handles = [] # type: list
incidents = [] # type: list
messages = client.receive_message(
QueueUrl=aws_queue_url,
MaxNumberOfMessages=max_number_of_messages,
VisibilityTimeout=5,
VisibilityTimeout=30,
WaitTimeSeconds=5,
)

if "Messages" not in messages.keys():
if len(incidents) == 0:
if incidents_created == 0:
if demisto.command() == 'fetch-incidents':
demisto.incidents([])
return messages, incidents, receipt_handles
Expand All @@ -177,12 +178,13 @@ def fetch_incidents(aws_client, aws_queue_url, max_fetch, parse_body_as_json):
for message in messages["Messages"]:
receipt_handles.append(message['ReceiptHandle'])
incidents.append(parse_incident_from_finding(message, parse_body_as_json))
if len(incidents) == max_fetch:
incidents_created += 1
if incidents_created == max_fetch:
break

demisto.incidents(incidents)
for receipt_handle in receipt_handles:
client.delete_message(QueueUrl=aws_queue_url, ReceiptHandle=receipt_handle)
demisto.incidents(incidents)
for receipt_handle in receipt_handles:
client.delete_message(QueueUrl=aws_queue_url, ReceiptHandle=receipt_handle)

except Exception as e:
return raise_error(e)
Expand Down
4 changes: 4 additions & 0 deletions Packs/AWS-SQS/ReleaseNotes/1_2_8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#### Integrations
##### AWS - SQS
- Fixed an issue where duplicates could be created during large fetches
2 changes: 1 addition & 1 deletion Packs/AWS-SQS/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "AWS - SQS",
"description": "Amazon Web Services Simple Queuing Service (SQS)",
"support": "xsoar",
"currentVersion": "1.2.7",
"currentVersion": "1.2.8",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 5848e08

Please sign in to comment.