Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 拒绝AWS API网关中针对特定IP的请求_Amazon Web Services_Aws Api Gateway - Fatal编程技术网

Amazon web services 拒绝AWS API网关中针对特定IP的请求

Amazon web services 拒绝AWS API网关中针对特定IP的请求,amazon-web-services,aws-api-gateway,Amazon Web Services,Aws Api Gateway,是否有办法拒绝特定IP的集成请求中的请求 目前我有这段代码,它可以工作,但是请求仍然传递到Lambda函数,并且我仍然返回常规的结果体。我试图在点击Lambda fn之前完全停止这个请求 #if($context.identity.sourceIp != "123.45.55.43") { "errorMessage" : "Error, not authorized" } #end #if($context.identity.sourceIp == "123.45.55.43

是否有办法拒绝特定IP的集成请求中的请求

目前我有这段代码,它可以工作,但是请求仍然传递到Lambda函数,并且我仍然返回常规的结果体。我试图在点击Lambda fn之前完全停止这个请求

#if($context.identity.sourceIp != "123.45.55.43")
  {
    "errorMessage" : "Error, not authorized"
  }
#end
#if($context.identity.sourceIp == "123.45.55.43")
  {
    "source_ip": "$context.identity.sourceIp"
  }
#else
  $broken
#end

这并不漂亮,但我想到的是:当IP与我想要的不匹配时,传递一个中断的请求。在本例中,我只希望来自
123.45.55.43
的请求能够通过,而其他所有请求都应该失败——我并不关心如何向客户端提供适当的响应。由于未定义
$breake
,因此我们不向Lambda fn传递任何内容

#if($context.identity.sourceIp != "123.45.55.43")
  {
    "errorMessage" : "Error, not authorized"
  }
#end
#if($context.identity.sourceIp == "123.45.55.43")
  {
    "source_ip": "$context.identity.sourceIp"
  }
#else
  $broken
#end

API最终有400个错误,但Lambda函数在其仪表板中没有显示任何新的调用/错误。对我来说很有用。

可能是@AndyHayden的复制品我不认为这是复制品。不是试图限制而是实际停止,我想我在下面找到了一个可行的(对我来说)解决方案。虽然限制并不完全相同,但本质上是相同的(具体来说,解决方案是相同的)。@我认为它们明显不同,因为我无法将下面的答案应用到“可能被愚弄”一文中的问题。下面的答案提供了停止请求的最短路径。正确,但您的答案发生在Lambda(API网关之后)IIUC中。:)