Search code examples
aws-lambdamicroservicesaws-api-gateway

Getting 403 forbidden error when calling API from node.js code, whereas working fine from Postman


I have microservices deployed on AWS lambda and node.js code deployed on EC2 instance.

When I am trying to access the microservice API from postman it is giving the correct response. But the same API if I call from node.js code, it fails with error code 403.

Error-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.

<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: TtGE8OD711qm0s6NPCNPl2ExUUJUa7l_J_-h5GDtPEWk4CFiWDkixg==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

The API is a simple GET API like

https://xxx.amazonaws.com/v1/session/verify_email_token?token=123456

I am not using CloudFront and I am using Https.


Solution

  • Following solution worked for me - Change the API Gateway endpoint from edge-optimized to regional.