- Newest
- Most votes
- Most comments
The 403 Forbidden error you're encountering with POST and OPTIONS methods from your Angular app to the AWS API Gateway HTTP API could be due to several reasons:
-
CORS Configuration: Although you've edited the CORS configuration, ensure that it's properly set up for all HTTP methods you intend to use (GET, POST, PUT, DELETE, OPTIONS). Make sure the 'Access-Control-Allow-Methods' header includes all these methods.
-
Lambda Function: Verify that your Lambda function is correctly handling all the HTTP methods, including OPTIONS for preflight requests. The function should return appropriate CORS headers for all requests.
-
API Gateway Configuration: Double-check that your API Gateway is configured to pass all necessary headers to and from your Lambda function. This includes CORS headers.
-
Angular HTTP Client: Ensure your Angular app is sending the correct headers with each request. You might need to add custom headers or modify existing ones.
-
Browser Security: Some browsers might block certain types of requests due to security policies. Check your browser's console for any security-related messages.
-
API Key or Authorization: Even though you mentioned not needing authorizers, verify that there isn't any unintended authorization or API key requirement set up on your API Gateway.
To troubleshoot:
- Use browser developer tools to inspect the exact request being sent and the response received.
- Check CloudWatch logs for your Lambda function to see if the requests are reaching it and how it's responding.
- Try adding explicit CORS headers in your Lambda function response.
- Ensure your Angular environment variables (apiURL) are correctly set.
If the issue persists after checking these points, you may need to review your API Gateway and Lambda configurations in more detail or consider reaching out to AWS support for further assistance.
Sources
Mock Api returning 403 Forbidden when calling it from a lambda function | AWS re:Post
answered 2 years ago
Relevant content
asked 2 years ago
