forked from TTLabs/EvaporateJS
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support to sign the request using amazon lambda
- Loading branch information
Showing
4 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
||
<title>Evaporate Example</title> | ||
|
||
<style> | ||
|
||
</style> | ||
|
||
|
||
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | ||
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.28.min.js"></script> | ||
<script language="javascript" type="text/javascript" src="../evaporate.js"></script> | ||
|
||
</head> | ||
<body> | ||
|
||
<div> | ||
<input type="file" id="files" multiple /> | ||
<div> | ||
|
||
|
||
<script language="javascript"> | ||
|
||
var files; | ||
|
||
var _e_ = new Evaporate({ | ||
aws_key: 'your aws_key here', | ||
bucket: 'your s3 bucket name here', | ||
lambda: new AWS.Lambda({ | ||
'region': 'lambda region', | ||
'accessKeyId': 'a key that can invoke the lambda function', | ||
'secretAccessKey': 'the secret' | ||
}), | ||
lambdaFunc: 'arn:aws:lambda:...:function:cw-signer' // arn of your lambda function | ||
}); | ||
|
||
$('#files').change(function(evt){ | ||
files = evt.target.files; | ||
|
||
for (var i = 0; i < files.length; i++){ | ||
|
||
_e_.add({ | ||
name: 'test_' + Math.floor(1000000000*Math.random()), | ||
file: files[i], | ||
notSignedHeadersAtInitiate: { | ||
'Cache-Control': 'max-age=3600' | ||
}, | ||
xAmzHeadersAtInitiate : { | ||
'x-amz-acl': 'public-read' | ||
}, | ||
signParams: { | ||
foo: 'bar', | ||
fooFunction: function() { | ||
return 'bar'; | ||
} | ||
}, | ||
signHeaders: { | ||
fooHeaderFunction: function() { | ||
return 'bar' | ||
}, | ||
fooHeader: 'bar' | ||
}, | ||
beforeSigner: function(xhr) { | ||
var requestDate = (new Date()).toISOString(); | ||
xhr.setRequestHeader('Request-Header', requestDate); | ||
}, | ||
complete: function(){ | ||
console.log('complete................yay!'); | ||
}, | ||
progress: function(progress){ | ||
console.log('making progress: ' + progress); | ||
} | ||
}); | ||
} | ||
|
||
$(evt.target).val(''); | ||
|
||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var crypto = require('crypto'); | ||
var secret = 'YOUR_AWS_SECRET_KEY'; | ||
|
||
exports.handler = function(event, context) { | ||
if (!event.to_sign) { | ||
context.fail('Missing to_sign param'); | ||
return; | ||
} | ||
context.succeed( | ||
crypto.createHmac('sha1', secret) | ||
.update(event.to_sign) | ||
.digest('base64') | ||
); | ||
}; |