我在处理 SNS 事件的 AWS Lambda 上运行了一个 Spring Cloud 函数。对于某些错误情况,我想触发自动 Lambda 重试或触发 SNS 服务的重试功能。SNS 重试策略采用默认配置。
我尝试返回带有 {"statusCode":500} 的 JSON,当我们在 aws 控制台中进行测试调用时,它正在工作。无论如何,当我们发送此状态时,不会触发函数的重试调用。
我们使用 SpringBootRequestHandler
public class CustomerUpdatePersonHandler extends SpringBootRequestHandler<SNSEvent, Response> {
}
@Component
public class CustomerUpdatePerson implements Function<SNSEvent, Response> {
@Override
public Response apply(final SNSEvent snsEvent) {
//when something goes wrong return 500 and trigger a retry
return new Response(500)
}
}
public class Response{
private int statusCode;
public Response(int code){
this.statusCode = code;
}
public int getStatusCode(){
retrun statusCode;
}
}