I have an S3 bucket, mybucket
, and I want to execute something when a new file is copied into that bucket. For the notifications, I want to use an SQS queue, notifiqueue
, because my goal is to access that queue with Laravel
Since I am creating my infrastructure in CloudFormation
, the resources are created like this:
NotificationQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 120
QueueName: 'NotificationQueue'
DataGateBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: BucketOwnerFullControl
BucketName: 'mybucket'
NotificationConfiguration:
QueueConfigurations:
- Event: 's3:ObjectCreated:*'
Queue: !GetAtt NotificationQueue.Arn
Each time a new file is saved on the bucket, S3 automatically creates a notification in SQS.
Sadly, the format of the payload is NOT COMPATIBLE with Laravel standard job payload, and if I run a worker process on the NotificationQueue
I get this error:
local.ERROR: Undefined index: job {"exception":"[object] (ErrorException(code: 0): Undefined index: job at .../vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:273)
To provide a more complete indication, here is what I get in the notification (after turning JSON into a PHP array)
array:1 [
"Records" => array:1 [
0 => array:9 [
"eventVersion" => "2.1"
"eventSource" => "aws:s3"
"awsRegion" => "eu-central-1"
"eventTime" => "2019-04-23T17:02:41.308Z"
"eventName" => "ObjectCreated:Put"
"userIdentity" => array:1 [
"principalId" => "AWS:XXXXXXXXXXXXXXXXXX"
]
"requestParameters" => array:1 [
"sourceIPAddress" => "217.64.198.7"
]
"responseElements" => array:2 [
"x-amz-request-id" => "602CE18B8DE0BE5C"
"x-amz-id-2" => "wA/A3Jl2XpoxBWJEgQzy11s6O28Cz9Wc6pVi6Ho1vnIrOjqsWkGozlUmqRdpYAfub0MqdF8d/YI="
]
"s3" => array:4 [
"s3SchemaVersion" => "1.0"
"configurationId" => "0d4eaa75-5730-495e-b6d4-368bf3690f30"
"bucket" => array:3 [
"name" => "mybucket"
"ownerIdentity" => array:1 [
"principalId" => "XXXXXXXXXXXXXXXXXX"
]
"arn" => "arn:aws:s3:::mybucket"
]
"object" => array:4 [
"key" => "dirName/myFile.txt"
"size" => 1991721
"eTag" => "824a20edad0091027b5d0fa6d78bb24f"
"sequencer" => "005CBF452E30AAC02A"
]
]
]
]
]
Which is the working / best / right way to access the notification using Laravel so that I can trigger some other option in response to the file upload ?