Sunday, March 10, 2019

Lambda read S3 object with S3 trigger

Configuring your Lambda function to read S3 object with S3 upload trigger


Are you new to Lambda and haven't quite got the test case figured out for S3 upload trigger? In the steps below, you'll build a new Python Lambda function from a blueprint and use the CloudWatch log to populate a new test case. This way you don't have to upload just to test your new function.
  1. Create a new Lambda Function
  2. Select "Use a blueprint"
  3. Search for "S3"
  4. Select "s3-get-object-python3"
  5.  Configure it using mostly default settings
    1. Function Name: of your choice
    2. Create a new role from AWS policy template
    3. Role Name: of your choice
    4. Select your own trigger bucket
    5. Select all object create event
    6. Leave prefix and Suffix blank
    7. Enable trigger
    8. Select Create Function
  6.  Uncomment line 12 that begins print('Received event: '
  7.  Upload a file to the bucket you select in the previous step
  8.  From the Lambda function console, go to Monitoring
  9. Go to View logs in CloudWatch - this will open a new tab into CloudWatch
  10. Click the latest and probably ONLY log stream
  11. View in TEXT (not rows)
  12. Copy the text like below as shown in your log screen into your clipboard
  13. Now go back to your Lambda function console
  14. Up by the top between Action and Test, click on the drop down and select Configure Test Event
  15. Create new test event (it does not matter what template you choose)
  16. Give it a name
  17. In the body, paste the string from previous step that you put in your clipboard (overwrite existing text)
  18. Save and then click Test
  19. Your Lambda function will behave as if you've just uploaded that same file again
  20. Now go edit the function to do what you want and test easily!

No comments:

Post a Comment

AWS WAF log4j query

How to query AWS WAF log for log4j attacks 1. Setup your Athena table using this instruction https://docs.aws.amazon.com/athena/latest/ug/wa...