drvntaomy06331839 2018-08-27 14:41
浏览 162
已采纳

aws sqs lambda:消息不再出现

I have followed standard aws lambda creation with sqs trigger. Then I sent message to sqs queue which then kicks lambda, which in turn writes to stdout. All good.

The issue is: I have not yet deleted receipt of the message and I expect the message to appear again for processing after the visibility period of 60 seconds(default). This is not happening, wonder why.

package main

import (
    "context"
    "fmt"
    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
)

func handler(ctx context.Context, sqsEvent events.SQSEvent) error {

    for _, message := range sqsEvent.Records {
        fmt.Println("Id", message.MessageId)
        fmt.Println("Source", message.EventSource)
        fmt.Println("Body", message.Body)
    }

    return nil
}

func main() {
    lambda.Start(handler)
}
  • 写回答

2条回答 默认 最新

  • drny20290570 2018-08-27 15:54
    关注

    Making an answer out of the conversation with the OP

    Question: Op wants to check how SQS retries sending events to lambda when events fail. Op provides the code for a lambda function written in Go

    Problem: Provided lambda does not fail so no retry behavior happens.

    Solution: Rewrite lambda so it always fail.

        func handler(ctx context.Context, sqsEvent events.SQSEvent) error {
    
        for _, message := range sqsEvent.Records {
            fmt.Println("Id", message.MessageId)
            fmt.Println("Source", message.EventSource)
            fmt.Println("Body", message.Body)
        }
    
        return error.New("Song by B.S.")
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?