AWS Lambda function REST API end point - 403 error

后端 未结 5 881
不知归路
不知归路 2021-01-04 00:06

I have an AWS Lambda function that is exposed as a REST API.

When it is invoked it via the Test button on aws lambda console, it works.

When it is invoked v

5条回答
  •  长情又很酷
    2021-01-04 00:36

    You have to first make sure that CORS is enable at AWS API Gateway if you are accessing it from different domain because, it is API gateway which is throwing 403 error not the lambda function. You can enable CORS for a method or for complete resource. Select Actions and then select Enable CORS . This will add OPTIONS method to the resource if not already exist.

    Enabling CORS on API gateway will make sure that all response headers will have Access-Control-Allow-Origin value set to '*' (i.e allow all origins, but you can specify specific origin e.g. http://localhost).

    Always make sure you are invoking correct URL. You can get url from Stage section of API Gateway or from Lambda Function (if you have set Lambda function as integration end point)

    You can see new headers set in Method and Integration responses.

提交回复
热议问题