aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

How to invoke s3 create object event using sam-local

Open shilpa-jindal opened this issue 9 years ago • 12 comments

I have written a Lambda function that uploads data from a file to Database when a new file is uploaded to S3. I have the test file on my local folder. How do i generate an S3 event which mimics file upload on s3 bucket by pointing to my local folder? For example, i have "test.txt" file sitting in /usr/local/samlocal-files/ folder on my local. So, how do i create S3 event in a way that S3Object object = amazonS3.getObject(new GetObjectRequest(s3Bucket, s3Key)); is able to read file "/usr/local/samlocal-files/test.txt" ?

shilpa-jindal avatar Oct 06 '17 22:10 shilpa-jindal

+1

kaarthikeyansp avatar Nov 07 '17 09:11 kaarthikeyansp

+1

I can't tell from the docs if:

  • this is not possible and we never said it was
  • we can simulate a local s3 in this way
  • we can proxy an actual s3 in this way

colwilson avatar Nov 08 '17 12:11 colwilson

That would be very helpful

pavelloz avatar Jan 16 '18 10:01 pavelloz

I have the same function and use minio to simulate the S3 locally

danilopopeye avatar Feb 09 '18 14:02 danilopopeye

@danilopopeye Would you please mind providing us an example project with your workaround?

jkomyno avatar Feb 28 '18 20:02 jkomyno

@jkomyno have a look in this doc aws-sdk-for-javascript-with-minio. This is basically what I did.

danilopopeye avatar Mar 07 '18 19:03 danilopopeye

sam local generate-event s3 is what you need. Give it a try

sanathkr avatar May 08 '18 23:05 sanathkr

Created event file sam local generate-event s3 >>event.json using SAM 0.3.0

sam local invoke -e event.json

Resulting timeout error at s3.getObject(params, (err, data) => {

Error 2018-06-21 16:44:00 Function 's3getobject' timed out after 15 seconds What could be the issue?

suneelthakur1980 avatar Jun 21 '18 11:06 suneelthakur1980

sam local generate-event s3 is what you need. Give it a try

This will generate an S3 object event. What we need is the ability to seed data into the "local S3 bucket resource" so it can be retrieved from the Lambda which is triggered by the event.

kristophbarbour avatar Dec 22 '21 03:12 kristophbarbour

This will generate an S3 object event. What we need is the ability to seed data into the "local S3 bucket resource" so it can be retrieved from the Lambda which is triggered by the event.

I was wondering if it is possible to simulate a S3 resource PUT and lambda-function fetching S3-object on trigger with sam local ?? Please let me know how can I do that ?

avimehenwal avatar Mar 08 '22 23:03 avimehenwal

This will generate an S3 object event. What we need is the ability to seed data into the "local S3 bucket resource" so it can be retrieved from the Lambda which is triggered by the event.

I was wondering if it is possible to simulate a S3 resource PUT and lambda-function fetching S3-object on trigger with sam local ?? Please let me know how can I do that ?

@avimehenwal I was looking for the same, Have you find any?

ARUNKUMAR-BHARATHI avatar Mar 10 '23 11:03 ARUNKUMAR-BHARATHI

here is what worked for me :

get options for each service: sam local generate-event s3 generate appropriate payload: sam local generate-event s3 put >> event.json run InsertFunctionName with the event sam local invoke InsertFunctionName -e event.json

praneethmendu avatar Jul 12 '24 12:07 praneethmendu