Eternalcode
Eternalcode

Reputation: 2412

Passing payload through AWS S3/Lambda Trigger

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.

Upvotes: 1

Views: 4273

Answers (2)

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

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.

Upvotes: 5

Vijayanath Viswanathan
Vijayanath Viswanathan

Reputation: 8571

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

Upvotes: 3

Related Questions