I'm currently utilizing the AWS CDK to construct my API Gateway REST API
My objective is to have my RestApi
configured to automatically return an HTTP 404 error, so I set it up as follows:
this.gateway = new apigw.RestApi(this, "Gateway", {
defaultIntegration: new apigw.MockIntegration({
passthroughBehavior: apigw.PassthroughBehavior.NEVER,
requestTemplates: {
"application/json": `{
"statusCode": 404
}`
},
integrationResponses: [{
statusCode: "404",
responseTemplates: {
"application/json": JSON.stringify({ "message": "Not Found" })
}
}]
}),
defaultMethodOptions: {
methodResponses: [
{
statusCode: "404"
}
]
}
});
// UPDATE:
this.gateway.root.resourceForPath("/foo")
this.gateway.root.resourceForPath("/foo/bar")
....
However, when I use a GET
with cURL on /foo
, instead of receiving a HTTP 404 error, I get a 403. What could be causing this discrepancy?
After reviewing the documentation (and inspecting the source code) for resourceForPath
, it seems that the default integration and default method options are indeed being correctly configured.
UPDATE:
Although I included
this.gateway.root.resourceForPath("/foo")
, the desired 404 error is still not being returned.