Ravikumar K
Ravikumar K

Reputation: 85

how to add proxy to s3 so i can consume service hosted in EC2 instance?

I am new to aws, I have hosted all UI in s3 bucket and used cloudfont too. Now i have hosted all the restApi in EC2 instance.

angular UI -> s3 bucket (example.com) backend SpringBoot restApi -> EC2 instance (api.exaple.com)

But can someone tell how to consume the API calls hosted in EC2 (api.example.com) from S3 (example.com) bucket/ cloud front.

I have hosted sprint boot rest api in EC2 instance (api.example.com:8080).

  1. s3 bucket says method not allowed for (GET, POST, PUT, DELETE) methods.
  2. For the above reason i hard coded the api.example.com in the code, so all my requests will redirect to api.example.com -> here the issue is browser will not allow cross origin.

Now i want to know how to make it work.

Upvotes: 0

Views: 462

Answers (1)

Anton
Anton

Reputation: 4062

You need to enable CORS (Cross-Origin Resource Sharing) on your S3 bucket.

Cross-origin resource sharing (CORS) defines a way for client web applications that are loaded in one domain to interact with resources in a different domain. With CORS support, you can build rich client-side web applications with Amazon S3 and selectively allow cross-origin access to your Amazon S3 resources.

Upvotes: 1

Related Questions