Skip to content

Angular application deployed in an AWS S3 Bucket cannot call extern API endpoint

0

Dear all,

I have uploaded in an AWS S3 Bucket a web application which I created by using Angular 18; the app calls via http (post method) an external mailer service (Sengrid), in order to send messages from a form.

Locally everything works; after uploading the app in the bucket, I tried to send a message from the same form but the message was not sent. By opening the dev console -> network, I read the following error:

405 Method Not Allowed Code: MethodNotAllowed Message: The specified method is not allowed against this resource. Method: POST ResourceType: OBJECT RequestId: -- HostId: --

**So, just to remark, the problem is not to access to the bucket from an extern resource - as I found many times by searching in Google; but in my case the application deployed in the S3 bucket should access to resources external to AWS. ** And yes, the Sengrid allows perfectly that method, as as said from local and from Postman everything works fine.

I tried many solutions - including changing the security settings of the bucket, as suggested in other discussion - but nothing works. How can I solve the problem?

Please find below a screen of the error.

Thank you very much

Enter image description here

1 Answer
0

Hi,

You are probably facing a CORS (Cross Origin Resource Sharing) issue since you loads from an S3 website as origin and try to access a url in another external domain. Such issues don't show up in local dev usually: they emerge when you load your to the hosting site (S3 here)

You have to adapt your Angular configuration to support CORS. I'd suggest to read this to do so: https://www.stackhawk.com/blog/angular-cors-guide-examples-and-how-to-enable-it/

Best,

Didier

EXPERT
answered 2 years ago
  • Thanks for your help and your time but, as said, locally the Angular application works perfectly and that error has nothing to do with the CORS of Angular - the CORS is already implemented at Angular level. Have you some other idea?

    PS: I add another detail in the original question, also with the way I implemented the CORS in my Angular application.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.