aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.6k stars 1.55k forks source link

CORS problem with AppConfig #3262

Closed darko-dev closed 3 years ago

darko-dev commented 4 years ago

Confirm by changing [ ] to [x] below:

Describe the question I am trying to use AWS AppConfig Service within my ReactJS App but I am having problem with CORS.

When I try to fetch my configuration with

  Application: 'XXXXXXX', /* required */
  ClientId: 'XXXXXXX', /* required */
  Configuration: 'XXXXXXX', /* required */
  Environment: 'XXXXXX', /* required */
  ClientConfigurationVersion: '1'
}, (err, data) => {
  console.log("err = ", err);
  console.log("data = ", data);
})

I am getting:Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

If it matters, I am using Amazon System Manager document as configuration source.

I am guessing there is a CORS policy configuration for AppConfig/System Manager service just like for the S3 and API Gateway services but I can't find it.

Any help appreciated!

ajredniwja commented 4 years ago

Hey @darko-dev apologies for late response, the AppConfig service doesn't support CORS at the moment.

Also check the comment: https://github.com/aws/aws-sdk-js/issues/2657#issuecomment-491902749

darko-dev commented 4 years ago

Thanks @ajredniwja !

Is there a guide/ tutorial on how to use this particular service from web apps? Is there a way to combine other AWS service with AppConfig to be able fetch the configuration from browser?

Edit: Someone suggested to use API Gateway which will invoke the service. Is this recommended way?

ajredniwja commented 4 years ago

There are different ways depending upon your use case, can you share what you are trying to do?

darko-dev commented 4 years ago

The idea was to use it as way to control a set of feature flags for the app done in ReactJS. Feature flags would control show/hide parts of the app and menus, for example.

ajredniwja commented 4 years ago

Yes, that can be used to overcome the problem, which would mean to create a proxy, which would call the AppConfig API. The browser client would then call the proxy instead of AppConfig API directly.

github-actions[bot] commented 3 years ago

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.