AWS SQS 随机分组多条消息?
AWS SQS groups multiple messages at random?
我有一个工作流程,ingests/transforms 一个大的 CSV,将其分成 20 个较小的部分,然后使用 SQS
/Lambda
将它们上传到 Postgres
。本质上,队列中的 20 条消息中的每条都应该代表一个文件。这会导致问题,因为消息被组合在一起,这样一个正在发送的消息将尝试处理多个 messages/files。 SQS
事件基本上是这样的:
{
"Records": [
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 1,
},
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 2,
},
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 3,
}
]
}
它试图用一个 lambda 调用处理所有三个。理想情况下,我希望像这样调用一个文件 20 次:
{
"Records": [
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 1,
},
]
}
这可能吗?
根据 documentation 你应该将 BatchSize
属性 设置为 1
.
BatchSize
The maximum number of items to retrieve in a single batch.
如果您使用的是 AWS 控制台,继续您的 lambda,单击 Add Trigger
select SQS
并设置 BatchSize
到 1
:
在 CloudFormation 中使用 sam 模板:
YourFunction:
Type: AWS::Serverless::Function
Properties:
Events:
SQSEvent:
Type: SQS
Properties:
Queue: YourQueue
BatchSize: 1
我有一个工作流程,ingests/transforms 一个大的 CSV,将其分成 20 个较小的部分,然后使用 SQS
/Lambda
将它们上传到 Postgres
。本质上,队列中的 20 条消息中的每条都应该代表一个文件。这会导致问题,因为消息被组合在一起,这样一个正在发送的消息将尝试处理多个 messages/files。 SQS
事件基本上是这样的:
{
"Records": [
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 1,
},
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 2,
},
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 3,
}
]
}
它试图用一个 lambda 调用处理所有三个。理想情况下,我希望像这样调用一个文件 20 次:
{
"Records": [
{
"messageId": guid,
"receiptHandle": hash ,
"body": file path 1,
},
]
}
这可能吗?
根据 documentation 你应该将 BatchSize
属性 设置为 1
.
BatchSize The maximum number of items to retrieve in a single batch.
如果您使用的是 AWS 控制台,继续您的 lambda,单击 Add Trigger
select SQS
并设置 BatchSize
到 1
:
在 CloudFormation 中使用 sam 模板:
YourFunction:
Type: AWS::Serverless::Function
Properties:
Events:
SQSEvent:
Type: SQS
Properties:
Queue: YourQueue
BatchSize: 1