Advertisement
uopspop

Untitled

Dec 30th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Invoke Lambad in Javascript</title>
  6. <script src="https://sdk.amazonaws.com/js/aws-sdk-2.92.0.min.js"></script>
  7. <script type="text/javascript">
  8. // Configure AWS SDK for JavaScript & set region and credentials
  9. // global variables to change for this tempalte
  10. var aws_region = 'us-west-2';
  11. var identity_pool_id = 'us-west-2:39f57ed5-cbc4-48d3-a174-2f9a2a460f0b';
  12. var lambda_function_name = 'slotpull';
  13.  
  14. // Initialize the Amazon Cognito credentials provider
  15. AWS.config.region = aws_region; // Region
  16. AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  17.     IdentityPoolId: identity_pool_id,
  18. });
  19.    
  20.     /// Prepare to call Lambda function
  21.     lambda = new AWS.Lambda({region: aws_region, apiVersion: '2015-03-31'});
  22.     var pullParams = {
  23.         FunctionName : lambda_function_name,
  24.         InvocationType : 'RequestResponse',
  25.         LogType : 'None'
  26.     };
  27.  
  28. /// CLIENT UI CODE ///
  29.  
  30.     function init() {
  31.         // Call the Lambda function to collect the results
  32.         lambda.invoke(pullParams, function(err, data) {
  33.             if (err) {
  34.                 prompt(err);
  35.             } else {
  36.                 pullResults = JSON.parse(data.Payload);
  37.                 console.log(pullResults);
  38.             }
  39.         });
  40.     };
  41.  
  42. </script>
  43.  
  44. </head>
  45.  
  46. <body>
  47.     <div>
  48.         <input id="clickMe" type="button" value="click me and check the console" onclick="init();" />
  49.     </div>
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement