简体   繁体   English

如何拒绝在短时间内发送两次相同的 POST 请求

[英]How to reject the same POST request sent twice in a short gap of time

I am wondering if there is a standard way to reject requests with the same body sent within a few seconds at the API gateway itself.我想知道是否有一种标准方法可以拒绝 API 网关本身在几秒钟内发送的具有相同正文的请求。

Forex: Reddit rejects if I try to post the same content within few seconds in a different group.外汇:如果我尝试在几秒钟内在不同的群组中发布相同的内容,Reddit 会拒绝。 Similarly, if I make a credit card payment for the second time, it automatically rejects it.同样,如果我第二次使用信用卡付款,它会自动拒绝。

I am wondering if there is a way to have the same behavior in the AWS API gateway itself so that we are not handling it in lambda functions with dynamoDB and stuff.我想知道是否有一种方法可以在AWS API 网关本身中具有相同的行为,这样我们就不会在 lambda 函数中使用 dynamoDB 和其他东西来处理它。

Looking forward to efficient ways of doing it.期待有效的方法。

The API Gateway currently doesn't offer a feature like that, you'd have to implement this yourself. API 网关目前提供这样的功能,您必须自己实现。

If I was to implement this, I'd probably use an in-memory cache like ElastiCache for Redis or Memcached as the storage backend for deduplications.如果我要实现这一点,我可能会使用内存缓存(如 ElastiCache 用于 Redis)或 Memcached 作为重复数据删除的存储后端。 For each incoming request I'd determine what makes it unique and create a hash from that.对于每个传入的请求,我将确定是什么使它独一无二并从中创建一个 hash 。

Then I check if that hash value is in the cache already.然后我检查 hash 值是否已经在缓存中。 If that's the case it 'sa duplicate and I reject the request.如果是这种情况,那就是重复的,我拒绝该请求。 If it isn't already in the cache, I'd add it with a time to live of n seconds (The time interval in which I wish to deduplicate).如果它尚未在缓存中,我将添加它的生存时间为n秒(我希望删除重复数据的时间间隔)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果应在短时间内发送大量电子邮件,如何在lambda中使用AWS SES? - How to use AWS SES inside lambda if a lot of emails should be sent in a short interval of time? 同时启动和意图请求? - Launch and intent request at the same time? 如何解码 AWS Cognito 发送的“状态”请求参数? - How to decode "state" request parameter sent by AWS Cognito? AWS Custom Lamba Authorizer第二次为来自客户端的单个请求调用了两次空事件对象 - AWS Custom Lamba Authorizer called twice for single request from client with empty event object second time 如何使用 TaskToken 两次回调同一个 step 函数? - How do you use a TaskToken to callback to the same step function twice? 504特定POST请求的网关超时 - 504 Gateway Time-out on specific POST request 如何使用 AWS Lambda 向邮递员 POST 请求 - How to POST request to postman using AWS Lambda 如何使用 GraphQL POST 请求进行授权获取? - How to do authorization fetch with GraphQL POST request? 如何使用 AWS 签名版本 4 签署 POST 请求 - How to sign POST request with AWS Signature Version 4 如何向 Cloudfront 发送发布请求? - How do I send a post request to Cloudfront?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM