I have an express server. I am trying to forward all requests to path /grqphql to an AWS gateway endpoint.
To achieve this I am using express-http-proxy
const proxy = require('express-http-proxy');
const app = express();
app.use('/graphql', proxy('https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/graphql'));
The /grapql endpoint is called via a apollo-graphql-client on a react frontend. The POST grapql reqests returns a Forbidden error.
Few things to note.
- The lambda function is private (in a vpc)
- The api gateway is protected with a custom authorization function (checks Authorization header). But I am passing this header, this is not the problem.
- I have deployed api gateway in a 'dev' stage.
This is coming from AWS Gateway. The response has the header x-amzn-errortype: ForbiddenException. I have reffered to the documentation regarding 403 errors. I suspect the issue is "Invoking a private API using public DNS names incorrectly" - in the linked documentaion.
Would appreciate some pointers on finding a workaround to this.
Edit:
Probably an issue with express-proxy middleware. As a woraround I've manually routed with axios. The following meets my requirments as this is a graphql endpoint.
router.post('/', (req, res) => {
const headers = {
'Content-Type': 'application/json',
'Authorization': req.get('Authorization')
}
axios({
method: 'post',
url: apiUrl,
headers: headers,
data: req.body
}).then((axiosResponse) => {
res.status(axiosResponse.status).send(axiosResponse.data);
}).catch((error) => {
res.status(error.response.status).send(error.response.data);
});