Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. A -- Copy this lambda policy
  2.  
  3. {
  4. "Version": "2012-10-17",
  5. "Statement": [
  6. {
  7. "Action": [
  8. "logs:CreateLogGroup",
  9. "logs:CreateLogStream",
  10. "logs:PutLogEvents"
  11. ],
  12. "Resource": "arn:aws:logs:*:*:*",
  13. "Effect": "Allow"
  14. },
  15. {
  16. "Action": [
  17. "dynamodb:PutItem",
  18. "dynamodb:UpdateItem",
  19. "dynamodb:DeleteItem"
  20. ],
  21. "Resource": "arn:aws:dynamodb:*:*:*",
  22. "Effect": "Allow"
  23. }
  24. ]
  25. }
  26.  
  27. B __ FIRST LAMBDA CODE
  28.  
  29. console.log('Loading Lambda function');
  30.  
  31. exports.handler = async (event, context, callback) => {
  32. let resultNum = Math.ceil(999.99);
  33.  
  34. callback(null, 'this is the original function (Math.ceil) = ' + resultNum);
  35. };
  36.  
  37. C __ SECOND LAMBDA CODE
  38.  
  39. console.log('Loading Lambda function');
  40.  
  41. exports.handler = async (event, context, callback) => {
  42. let resultNum = Math.floor(999.99);
  43.  
  44. callback(null, 'this is the canary function (Math.floor) = ' + resultNum);
  45. };
  46.  
  47.  
  48. ------------------
  49.  
  50. import json
  51.  
  52. print('Loading your function')
  53.  
  54. def lambda_handler(event, context):
  55. #print("Received event: " + json.dumps(event, indent=2))
  56. # print statements actually get printed to the logs.
  57. print("message --> " + event['message'])
  58.  
  59. # Actually returning the value of the 'message' key.
  60. return event['message']
  61.  
  62. # Raising an exception if something goes wrong...
  63. raise Exception('Something went wrong!')
  64.  
  65.  
  66. --------------------
  67.  
  68. import json
  69.  
  70. print("STARTING NEW INVOCATION!!!")
  71.  
  72. def lambda_handler(event, context):
  73. # Setting variables to equal values from the event object passed in.
  74. bucket = event['Records'][0]['s3']['bucket']['name']
  75. region = event['Records'][0]['awsRegion']
  76. object = event['Records'][0]['s3']['object']['key']
  77. user = event['Records'][0]['userIdentity']['principalId']
  78.  
  79. print("Bucket: " + bucket)
  80. print("Region: " + region)
  81. print("User is " + user)
  82.  
  83. return(object)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement