API Gateway is returning 403 Forbidden when being called from ECS - amazon-ec2

I have set up a API gateway in AWS, and when I am able to call it from an application running in my laptop without any issue. However, it's giving me 403 forbidden error when I deploy the app in ECS on Fargate and call the same URL of API gateway.
I've confirmed the API gateway has been deployed and I am passing the stage name correctly.
This is the error message I am getting with 403 HTTP status code.
header([Server:"Server", Content-Type:"application/json", Content-Length:"24", Connection:"keep-alive", x-amzn-RequestId:"7e198xx8-5386-4xx7-axxf-a38cf78618b7", x-amzn-ErrorType:"ForbiddenException", x-amz-apigw-id:"cWxx5GSWXXcFuVg="])
{
"message": "Forbidden"
}
And I am using this base endpoint URL
https://{api-id}.execute-api.(region-id}.amazonaws.com/{stage}
I have tried with various endpoint types (Regional, Edge, Private), but none of them were successful. I might have used wrong URL though.
Do you have any idea what could be wrong in this case?

Related

API Gateway and Lambda Proxy integration {"message": "Internal server error"}

I have implemented a solution to integrate API Gateway REST API with AWS Lambda. Lambda function uses two URL Query string parameters for further processing.
When API is tested using the API Gateway console "Test" button I am getting Status Code:200. But when I invoke API from a EC2 Linux machine I am getting {"message": "Internal server error"}.
On checking the logs: Only one URL Query parameter string is passed to Lambda "Event" and the second parameter is lost.
Can anyone suggest what can be the reason here ?

API server block request from GuzzleHttp

I have 2 servers which are API server and Client server ....
Both server using Google Cloud server and I use Laravel framework to develop my system...
So, currently the problem is, it return 403 error when calling API (to API server) using GuzzleHttp (from Client Server).....
But after I change the user agent to curl/7.65.3, suddenly it is working fine...
But I want to know why??? Is there any other solution without changing the user-agent???
Thanks
What is your use method? If GET you can refer to:
GET Requests That Include a Body
If a viewer GET request includes a body, CloudFront returns an HTTP status code 403 (Forbidden) to the viewer.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html

403 error response from IIS on almost alternate request while load testing api

I have a web api which is deployed on IIS.
Api's are going through load test using load runner and almost on all alternative api call, getting 403 error response code, struggling to identify the issue, call is not going to the API, its returned back from IIS
I am doing bearer token authorization, somehow token which were incoming with each request were not valid, that is why the issue was occurring, to overcome this we have increased the lifetime of token to 1 hour and request load test team to generate the token once and send that token only with each request so that we can now see the proper execution time for each end point.
403 error indicates that access to the requested URL by the client is Forbidden for some reason. you need to provide detailed error message snapshot and what is the sub status code. and check that you assign this permission to the site folder:1) IIS_IUSRS,2)NETWORK SERVICE,3)IUSR

API Gateway WebSocket API postConnection timeout

I'm trying to set up a WebSocket API on API Gateway. I'm following the basic tutorial, and I have everything up and running -> Routes for $connect, $disconnect, "test", $default. I am able to connect to the API, store the connectionId in Redis, and retrieve it when accessing from the test route.
The problem is when I try to send back a message from my lambda (single lambda handling all routes). I'm using the following code
const apigwManagementApi = new AWS.ApiGatewayManagementApi({
apiVersion: '2018-11-29',
endpoint: `https://${event.requestContext.domainName}/${event.requestContext.stage}`
});
Then I call
await apigwManagementApi.postToConnection({
ConnectionId: connectionId,
Data: `Echo: ${data}`
}).promise()
This is only called on the "test" route.
All of this is as per their guide. I had to add a patch to be able to make postConnection work, again, as per their tutorial. The problem is when the above method is called I get a Internal Server Error message from the API Gateway and the lambda times out after 3 seconds.
There is very little info on this method. I'm not sure what is causing the internal server error. I have checked the endpoint and the connectionId, both are correct.
What am I doing wrong? Any suggestions?
So the problem wasn't the actual lambda but the fact that it wasn't set up in a VPC that had access to the Internet. So if you're lambda has VPC enabled, make sure you it has a NAT gateway and Internet gateway set up.

AWS api gateway - http proxy should take status code from origin

I am currently trying to setup AWS Api Gateway, to proxy to another api, that has fully functional methods, response content, status codes etc. This is fairly simple to setup, but I have noticed that the Api Gateway always returns 200 OK no matter what the origin api responds with.
Fx. if there was a bad request (in the origin api) which results in a error message in JSON and a 400 Bad Request, the Api Gateway will respond with a the exact same error message, but a status code of 200 OK
If I remove all settings from the Message Response in the API Gateway web-interface, I get an internal error in the API Gateway. Can it be true that I have to map all the different status codes from the origin api manually in the Api Gateway?
I would prefer if it was possible to just let the status code (as well as the response, which currently works great) pass through, and not have the Api Gateway touch it in any way.
Proxy integration can be used to achieve this. In this case, it is HTTP Proxy. Lambda Proxy integration can also be used but will need some code logic in lambda. API GW will then return the result as-is.
You are correct that currently when using API Gateway you are required to map all response codes in your integration responses. We have heard this "pass through" request from other customers and we may consider including this in future updates to the service.

Resources