Simple module to calculate Authorization
header for Amazon AWS REST requests, for Parse.com.
- Put 'aws-sign.js' file into your 'cloud/modules/' folder.
- Require module in Cloud Code.
var AwsSign = require('cloud/modules/aws-sign.js');
var signer = new AwsSign({
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
});
var opts = {
method: 'PUT',
url: 'http://johnsmith.s3.amazonaws.com/photos/puppy.jpg',
headers: { ... },
... // Other request options, ignored by AwsSign.
body: {}
success: function() {},
error: function() {}
};
signer.sign(opts);
Parse.Cloud.httpRequest(opts);
or
var AwsSign = require('cloud/modules/aws-sign.js');
var signer = new AwsSign({
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
});
Parse.Cloud.httpRequest(signer.sign({
method: 'PUT',
url: 'http://johnsmith.s3.amazonaws.com/photos/puppy.jpg',
headers: { ... },
... // Other request options, ignored by AwsSign.
body: {}
success: function() {},
error: function() {}
}));
The following keys are mandatory:
method
url
Others are optional. A date header (headers.date
) will be added for you if it is not already set.