forked from ramonck/getlambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getlambda.html
46 lines (39 loc) · 1.28 KB
/
getlambda.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<script src="https://github.com/aws/aws-sdk-js/blob/master/dist/aws-sdk.min.js"></script>
<script>
var getVar1 = getUrlVars()["id"];
var getVar2 = getUrlVars()["page"]
var lambdaArgs = {id:[getVar1], page:getVar2};
var LAMBDAFUNCTIONNAME = "My-Good-Old-Function";
var ACCESSKEYID = "My-ACCESS-Key-ID";
var SECRETACCESSKEY = "My-SECRET-ACCESS-KEY";
var MYREGION = "us-east-1";
function LambdaClient(options){
this.options = options || {};
this.lambdaClient = new AWS.Lambda(options);
this.invoke = function(functionName, invokeArgs){
var callId = functionName;
var params = {
FunctionName: functionName,
InvokeArgs: JSON.stringify({"args": invokeArgs})
}
console.log(invokeArgs);
this.lambdaClient.invokeAsync(params, function(err, data) {
if (err) { throw 'Erro: '+err } else { console.log(data);}
});
}
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
AWS.config.update({accessKeyId: ACCESSKEYID, secretAccessKey: SECRETACCESSKEY, region: MYREGION});
var lambdaJob = new LambdaClient();
lambdaJob.invoke(LAMBDAFUNCTIONNAME, lambdaArgs);
</script>
</head>
</html>