I'm using a HTTP API Gateway to trigger a lambda invocation. When I use the url from postman, no issues. When I use it from my browser, it always makes a 2nd request, for the favicon.
Is there anyway in the gateway itself to block the favicon request from getting to the lambda?
I'm using the following terraform:
resource "aws_apigatewayv2_api" "retry_api" {
name = "${var.environment}_${var.cdp_domain}_retry_api"
protocol_type = "HTTP"
description = "To pass commands into the retry lambda."
target = module.retry-support.etl_lambda_arn
}
resource "aws_lambda_permission" "allow_retry_api" {
statement_id = "AllowAPIgatewayInvokation"
action = "lambda:InvokeFunction"
function_name = module.retry-support.etl_lambda_arn
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.retry_api.execution_arn}/*/*"
}
This won't block the favicon request made from the browser, rather won't invoke the Lambda for those requests.
Assuming the API endpoint is
/hello
and the http method isGET
, you can restrictapi-gateway
to invoke the lambda for only this URL. The format would be like this.So the
source_arn
inaws_lambda_permission
would change to something like thisThe answer assumes the existing / in the end is for
apiId
andstage
respectively. Otherwise check the value for${aws_apigatewayv2_api.retry_api.execution_arn}
and make modifications accordingly.This answer can also help. You can provide the
openapi specification
in the body for your supportedpath
only. For the above case the relevant path section of theopenapi specification
invoking a Lambda namedHelloWorldFunction
would look likeHere is a link to OpenApi Specification.