aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js (In Maintenance Mode, End-of-Life on 09/08/2025). The AWS SDK for JavaScript v3 in the browser and Node.js is available here: https://github.com/aws/aws-sdk-js-v3
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.6k stars 1.55k forks source link

Connect CORS - sdk javascript #3206

Closed nicosli closed 3 years ago

nicosli commented 4 years ago

I have this code in my vue project:

AWS.config.region = 'us-west-2'; // Región
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'IDENTIFY_POOL_ID',
})

// Create a new service object
this.connect = new AWS.Connect({
    apiVersion: '2017-08-08',
    params: {
        signatureVersion: 'v4'
    }
});

var params = {
    InstanceId: 'INSTANCE_ID', /* required */
    MaxResults: 10,
};
this.connect.listUsers(params, function(err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
})

And the result is

Access to XMLHttpRequest at 'https://connect.us-west-2.amazonaws.com/users-summary/INSTANCE_ID?maxResults=10' from origin 'https://local.project.mx:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Response Header

content-length: 259
content-type: application/json
date: Thu, 09 Apr 2020 03:08:24 GMT
status: 403
x-amz-apigw-id: KsuyQFeXPHcF84g=
x-amzn-errortype: AccessDeniedException
x-amzn-requestid: bfef631b-582b-4e61-9d82-b1d8a5064d61

SDK version number aws-sdk@2.656.0

Thank you in advance

ajredniwja commented 4 years ago

Hey @nicosli thank-you for reaching out to us with your issue, I am seeing the similar error while reproducing this, let me confirm with the service team if they support CORS for connect or not.

nicosli commented 4 years ago

Hey @nicosli thank-you for reaching out to us with your issue, I am seeing the similar error while reproducing this, let me confirm with the service team if they support CORS for connect or not.

Hi, do you have news?

ddo88 commented 4 years ago

Same problem here but with datasync

AWS.config.region = 'us-east-1'; AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: 'MyPoolId'}); var datasync = new AWS.DataSync(); var params = { TaskExecutionArn: 'taskARN' }; datasync.describeTaskExecution(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response });

result imagen

josefyendif commented 4 years ago

How to solve this, i am also facing same issue

ajredniwja commented 4 years ago

To solve the issue you might want to use, API gateway. Which is basically creating a proxy which will call the Connect or datasync API and then the browser can make calls to that.

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.