相关疑难解决方法(0)

如何从 lambda 触发器将消息返回给 SQS

我有从 SQS 队列读取消息的 lambda 触发器。在某些情况下,消息可能尚未准备好进行处理,因此我想将消息放回队列中 1 分钟,然后重试。目前,我正在创建此客户记录的另一个副本并将此新副本发布到队列中。我是否有理由/方式将原始记录保留在队列中而不是创建新记录

def postToQueue(customer):

    if 'attemptCount' in customer.keys():
        attemptCount = int(customer["attemptCount"]) + 1
    else:
        attemptCount = 2
    customer["attemptCount"] = attemptCount

    # Get the service resource
    sqs = boto3.resource('sqs')

    # Get the queue
    queue = sqs.get_queue_by_name(QueueName='testCustomerQueue')
response = queue.send_message(MessageBody=json.dumps(customer), DelaySeconds=60)

    print('customer postback: ', customer)
    print ('response from writing ot the queue is: ', response)

#main function
for record in event['Records']:
    if 'body' in record.keys():
        customer = json.loads(record['body'])
        print("attempting to process customer", customer, " at: ", datetime.datetime.now()) …
Run Code Online (Sandbox Code Playgroud)

amazon-sqs aws-lambda

0
推荐指数
1
解决办法
5348
查看次数

标签 统计

amazon-sqs ×1

aws-lambda ×1