I have a WebDialog that needs to access AWS EC2 instances to collect data to modify different parts of the Dialog. I would like to do the requests directly in Javascript to make the experience smoother for the user. AWS Javascript SDK
I am using SketchUp 2015 on macos Mojave.
Unfortunately I am having an ‘access forbidden error’ when I make a request to AWS from a webdialog, but the same code works fine when used outside Sketchup (in both Chrome and Safari).
Failed to load resource: the server responded with a status of 403 (Forbidden)
To give you an idea, this is the code:
function get_ip_address() {
var myCredentials = new AWS.Credentials({
accessKeyId: 'AKID', secretAccessKey: 'SECRET'
});
var ec2 = new AWS.EC2({apiVersion: '2016-11-15', region: 'eu-west-1', credentials: myCredentials});
var params = {
DryRun: false
};
request = ec2.describeInstances(params, function (err, data) {
if (err) {
console.log("Error", err.stack);
} else {
// console.log("Success", JSON.stringify(data));
instances = data['Reservations'];
// console.log(instances.length);
var ip = data['Reservations'][0]['Instances'][0]['PublicIpAddress'];
console.log(ip);
return ip;
}
});
}
To debug the error I am using the Web Inspector and when I look at the Nwtwork/Header I notice some differences between Safari (browser) and WebDialog (SU).
Safari
Summary
URL: https://ec2.eu-west-1.amazonaws.com/
Status: 200 OK
Source: Network
Address: 54.239.39.230:443
Request
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Authorization: AWS4-HMAC-SHA256 Credential=AKIAI6HTO376SMZWCTOQ/20190610/eu-west-1/ec2/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=c574c33b2963156257cd1f796b5a05cd4eefbc8c7e8d01ebe9908e5b75033638
Host: ec2.eu-west-1.amazonaws.com
Accept-Language: en-gb
Accept-Encoding: br, gzip, deflate
Origin: http://127.0.0.1:5500
Content-Length: 56
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15
Referer: http://127.0.0.1:5500/async/index.html
Connection: keep-alive
X-Amz-Date: 20190610T061250Z
X-Amz-User-Agent: aws-sdk-js/2.471.0 callback
X-Amz-Content-Sha256: 98e80202d1fe591a475a878de986416b75251c1035634dba690e4af74b6dd2cd
WebDialog
Summary
URL: https://ec2.eu-west-1.amazonaws.com/
Status: 403 Forbidden
Source: Network
Request
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: file://
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) SketchUp/15.3 (Mac; Safari)
Authorization: AWS4-HMAC-SHA256 Credential=AKIAI6HTO376SMZWCTOQ/20190610/eu-west-1/ec2/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=ba55d00928cf5cf44f7c66dc51b0a2d6e9ecbc4c7be81f5f1c117477ad13a3e1
Content-Length: 61
X-Amz-Content-Sha256: 98bdc72894a762ce7167f5c957e48aa89938a39d0f2554c92d66474ca521a1f4
X-Amz-User-Agent: aws-sdk-js/2.471.0 callback
X-Amz-Date: 20190610T060223Z
I am not an expert, so the only difference that I see is in the origin - file://
vs http://127.0.0.1:5500
.
Could this be a problem? Any suggestion?