0

I am new to the AWS platform. I have invoked a lambda function through AWS CLI.

aws lambda invoke --function-name CFT ... --payload file://${DATA_TMP}/affl_ftp_config.json ${DATA_LOG}/outfile.txt

Here, The Payload is a json file

{
  "s3_bucket": "fanatics.dev.internal.confidential",
  ....
  "date": "20160813"
}

This json file is being used as part of event object in my lambda handler.

Is it possible to have this behavior configured when a S3 file is uploaded and it automatically triggers a Lambda function?

For e.g.,

I upload a file in a S3_bucket that will trigger a lambda function with the json payload shown above.

Eternalcode
  • 2,153
  • 3
  • 19
  • 28

2 Answers2

4

No, you can't.

The Lambda function triggered by an S3 upload provides information about the new object (region, bucket, key, version-id if the bucket is versioned) but does not provide the object payload.

See the documented S3 Event Message Structure. This is what a Lambda function invoked by S3 will receive.

So, the Lambda function invoked by the S3 event must then fetch the object from S3 in order to access the payload.

So, either your existing lambda function will need to be modified, or you'll need a new lambda function to respond to the event, fetch the payload, and then call the original function.

Note also that if these events are triggered by overwrites of existing objects, then you will want versioning enabled on your bucket and you'll want to use GetObjectVersion to fetch the payload with the explicit versionId in the event, because GetObject (without specifying the version) may return stale data on overwrites.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
3

Yes you can. S3 is one of the Lambda triggers. Please read more details here

Vijayanath Viswanathan
  • 8,027
  • 3
  • 25
  • 43
  • 1
    Minor comment: the event that triggers the Lambda function will include a reference to the S3 object that triggered the event, rather than including the body of the S3 object as the payload, but it's simple to retrieve the object's contents (see https://stackoverflow.com/questions/30651502/how-to-get-contents-of-a-text-file-from-aws-s3-using-a-lambda-function/30655755#30655755). – jarmod Sep 26 '17 at 18:57