본문 바로가기

AWS/Data

[NEW] Amazon SQS launches the Extended Client Library for Python to support payloads up to 2GB

Amazon Simple Queue Service(SQS)는 대용량 메시지 페이로드를 보내고 받을 수 있는 오픈 소스 Python용 확장 클라이언트 라이브러리를 출시합니다. Amazon SQS는 마이크로서비스, 분산 시스템, 서버리스 애

aws.amazon.com](https://aws.amazon.com/about-aws/whats-new/2024/02/amazon-sqs-extended-client-library-python-payloads/)

이제 Amazon Simple Queue Service(SQS)에서 Python을 지원하는 오픈소스 확장 라이브러리 출시하였습니다. 해당 라이브를 사용하시면 용량이 큰 메세지를 받거나 전송하실수 있습니다. Amazon SQS는 풀매니지드 메세징 큐 서비스로 마이크로서비스, 분산 시스템, 그리고 서버리스 어플리케이션 들을 디커플링 하거나 확장할 수 있습니다.

Python 전용 확장클라이언트 라이브러리를 사용하신다면 256KB 보다 크고 최대 2GB 까지 크기의 메세지를 제어할수 있습니다. 해당 라이브러리는 실제로 S3에 실제 Payload를 저장하고, 저장된 S3 객체의 참조(경로)가 포함된 메세지를 Amazon SQS 대기열로 보냅니다. 또한 해당 라이브러리는 JAVA용으로 먼저 지원하고 있었습니다. 이제 고객은 큰 사이즈의 메세지를 Amazon SNS를 통해서 Fan-out 할수있습니다.


 

테스트 Payload는 JSON dummy data | Demos (microsoftedge.github.io) 링크를 가져와서 진행하였습니다.

 

테스트의 사용한 코드를 다음과 같습니다.

import boto3
import sqs_extended_client
import json
import time

sqs_extended_client = boto3.client("sqs")
sqs_extended_client.large_payload_support = "<bucket-name>"
sqs_extended_client.use_legacy_attribute = False
sqs_extended_client.always_through_s3 = False # 이 옵션은 혹시 무조건 S3를 통하지 않으시려면 False로 두고 사용하시면 됩니다.

# Creating a SQS Queue and extracting it's Queue URL
queue = sqs_extended_client.create_queue(
    QueueName = "DemoPreparationQueue"
)
queue_url = sqs_extended_client.get_queue_url(
    QueueName = "DemoPreparationQueue"
)['QueueUrl']

# # Creating a S3 bucket using the S3 client (이미 버킷을 생성했기에 제외하였습니다)
# sqs_extended_client.s3_client.create_bucket(Bucket=sqs_extended_client.large_payload_support,
#                                             CreateBucketConfiguration={'LocationConstraint': 'ap-northeast-2'})

list_time = []
payload_size = "1MB"
# Sending a large message
for i in range(0,100):
    f = open(rf"amazon-sqs-python-extended-client-lib\sample_data\{payload_size}.json", "r")
    large_message = json.dumps(json.load(f))
    f.close()

    ns = time.time_ns()
    send_message_response = sqs_extended_client.send_message(
        QueueUrl=queue_url,
        MessageBody=large_message
    )
    assert send_message_response['ResponseMetadata']['HTTPStatusCode'] == 200
    list_time.append((time.time_ns() - ns)// 1_000_000)    


receive_message_response = sqs_extended_client.receive_message(
    QueueUrl=queue_url,
    MessageAttributeNames=['All']
)
assert receive_message_response['Messages'][0]['Body'] == large_message
receipt_handle = receive_message_response['Messages'][0]['ReceiptHandle']
print(receipt_handle)
print(receive_message_response)
    
print(f"{payload_size} Send Time(avg)",sum(list_time)/100)

 

실제 해당 코드를 돌렸을때 Retrun 값은 다음과 같이 보입니다.

CLI 결과 값

잘 보시면 Payload가 돌아오는 것을 확인할 수 있고 평균 전송 시간은 253ms 정도로 나오는 것으로 보입니다. 물론 최근에 등장한 S3 Express One Zone 기준으로는 결과가 좀 달라질수 있으나(사실 해당 라이브러리에서 해당 버킷을 지원하는 것으로 보이지는 않습니다).. 로컬PC는 서울리전에 가까우니 일딴 서울리전 기준으로 테스트 하였습니다.

 

Amazone SQS > Queues > {생성된 큐명} > Send and receive messages

 

실제 AWS SQS 서비스에 접속해 보면 위의 CLI에서 보이는 Payload와 다른 단순한 정보를 담고 있는 것이 보입니다. 해당 Key 값을 S3에서 한번 찾아보도록 하겠습니다,

 

Amazon S3 콘솔

 

해당 Key로 되어있는 파일명을 확인할수 있으며 해당 파일은 JSON형태로 되어있습니다. 아래의 전체의 Payload를 보여주기에는 량이 많아서 다운받은 파일의 일부 Payload를 보여드리겠습니다.

 

Notpad++ 다운받아서 본 파일

 

 

결론으로 해당 기능을 통해서 SQS에서 보다 많은 Payload 전송이 어려워서 사용이 어려웠던 분들에게는 좋은 소식일거 같습니다. 실제로 256KB를 S3를 통하지 않는 기준으로 테스트 해보았을때 메세지당 속도가 50~100ms 정도 차이가 났으며 이는 실제 전송/수신 속도가 매우 빠른 50ms~100ms의 use case를 제외하고는 사용이 가능할것으로 보입니다.

 

'AWS > Data' 카테고리의 다른 글

[Snowflake <> AWS] Iceberg 테이블 연동성과 관련한 특이사항  (0) 2024.02.28