Guest User

Untitled

a guest
Apr 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <form>
  2. <label for="username">Add Username:</label>
  3. <textarea id="username"></textarea>
  4.  
  5. <button id='submitButton'>Submit</button>
  6. </form>
  7.  
  8. <script
  9. src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">
  10. </script>
  11. <script type="text/javascript">
  12. var API_URL = 'https://quovje1gi8.execute-api.us-east-2.amazonaws.com/production/accounts';
  13.  
  14. $(document).ready(function(){
  15. $.ajax({
  16. type:'GET',
  17. url: API_URL,
  18.  
  19. success: function(data){
  20. $('#accounts').html('');
  21.  
  22. data.Items.forEach(function(accountsItem){
  23. $('#accounts').append('<p>' + accountsItem.username + '</p>');
  24. })
  25. }
  26. });
  27. });
  28.  
  29. $('#submitButton').on('click', function(){
  30. $.ajax({
  31. type:'POST',
  32. url: API_URL,
  33. data: JSON.stringify({"username": $('#username').val()}),
  34. contentType: "application/json",
  35.  
  36. success: function(data){
  37. location.reload();
  38. }
  39. });
  40.  
  41. return false;
  42.  
  43. });
  44.  
  45. 'use strict';
  46.  
  47. console.log('Starting Function');
  48.  
  49. const AWS = require('aws-sdk');
  50. const docClient = new AWS.DynamoDB.DocumentClient({region:'us-east-2'});
  51.  
  52. exports.handler = function(e, ctx, callback) {
  53.  
  54. var params = {
  55. Item: {
  56. user_id: ,
  57. date: Date.now(),
  58. username: "",
  59. password: "",
  60. name: "",
  61. location: "",
  62. field: "",
  63. company: ""
  64. },
  65.  
  66. TableName: 'accounts'
  67. };
  68.  
  69. docClient.put(params, function(err, data){
  70. if(err){
  71. callback(err, null);
  72. }
  73. else{
  74. callback(null, data);
  75. }
  76. });
  77.  
  78. }
Add Comment
Please, Sign In to add comment