"""Boto3 sqs message operations.""" import json from typing import Any from owsresponse import response from transcoding import config from transcoding.connectors import sqs def send_sqs_message( queue_url: str, message: dict[str, Any], message_group_id: str, delay_seconds: int = config.SQS_DELAY_TIMEOUT, ) -> response.Response: """Send sqs message to given queue_url. Args: queue_url (str): Destination queue url. message (dict): Message body. message_group_id (str): Message group id for FIFO queue. delay_seconds (int): SQS message delay time. Returns: response.Response: Saved status info or error. """ sqs_client = sqs.get_sqs_client() try: result = sqs_client.send_message( QueueUrl=queue_url, MessageBody=json.dumps(message), DelaySeconds=delay_seconds, MessageGroupId=message_group_id, ) return response.Response(result) except Exception as error: return response.create_fatal_response( "Failed to send sqs message with error: {msg}".format(msg=str(error)) )