forked from brianklaas/awsPlaybox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.cfm
More file actions
executable file
·68 lines (57 loc) · 2.08 KB
/
lambda.cfm
File metadata and controls
executable file
·68 lines (57 loc) · 2.08 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<cfset lambdaFunctionResult = "" />
<cfif structKeyExists(URL, "invokeFunction")>
<cfscript>
payload = {
"firstName": "Brian",
"lastName": "Klaas",
"email": "brian.klaas@gmail.com",
"classes": [
{
"courseNumber": "260.710.81",
"role": "Faculty"
},
{
"courseNumber": "120.641.01",
"role": "Student"
}
]
}
jsonPayload = serializeJSON(payload);
// You need uncomment the line below if you have the "Prefix serialized JSON with " option turned on in the ColdFusion administrator.
// jsonPayload = replace(jsonPayload,"//","");
lambda = application.awsServiceFactory.createServiceObject('lambda');
invokeRequest = CreateObject('java', 'com.amazonaws.services.lambda.model.InvokeRequest').init();
invokeRequest.setFunctionName(application.awsResources.lambdaFunctionARN);
invokeRequest.setPayload(jsonPayload);
result = variables.lambda.invoke(invokeRequest);
sourcePayload = result.getPayload();
// The payload returned from a Lambda function invocation in the Java SDK is always a Java binary stream. As such, it needs to be decoded into a string of characters.
charset = CreateObject('java', 'java.nio.charset.Charset').forName("UTF-8");
charsetDecoder = charset.newDecoder();
lambdaFunctionResult = charsetDecoder.decode(sourcePayload).toString();
</cfscript>
</cfif>
<cfcontent reset="true" />
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AWS Playbox: AWS Service Demos</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,800' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="assets/styles.css?v=1.0">
</head>
<body>
<div align="center">
<div id="mainBox">
<h3>AWS Service Demos:</h3>
<h1>Lambda Function Invocation</h1>
<cfif Len(lambdaFunctionResult)>
<p>Result of function invocation:</p>
<p><cfoutput>#lambdaFunctionResult#</cfoutput></p>
</cfif>
<p><a href="lambda.cfm?invokeFunction=1">Invoke Demo Function</a></p>
<p align="right" ><a href="index.cfm" class="homeButton">Home</a></p>
</div>
</div>
</body>
</html>