title: How to intercept a new file on S3 using Laravel Queues?
body: <p>I have an S3 bucket, <code>mybucket</code>, 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, <code>notifiqueue</code>, because my goal is to access that queue with <code>Laravel</code></p>
  
  <p>Since I am creating my infrastructure in <code>CloudFormation</code>, the resources are created like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Each time a new file is saved on the bucket, S3 automatically creates a notification in SQS.</p>
  
  <p>Sadly, the format of the payload is NOT COMPATIBLE with Laravel standard job payload, and if I run a worker process on the <code>NotificationQueue</code> I get this error:</p>
  
  <pre><code>local.ERROR: Undefined index: job {"exception":"[object] (ErrorException(code: 0): Undefined index: job at .../vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:273)
  </code></pre>
  
  <p>To provide a more complete indication, here is what I get in the notification (after turning JSON into a PHP array)</p>
  
  <pre><code>array:1 [
    "Records" =&gt; array:1 [
      0 =&gt; array:9 [
        "eventVersion" =&gt; "2.1"
        "eventSource" =&gt; "aws:s3"
        "awsRegion" =&gt; "eu-central-1"
        "eventTime" =&gt; "2019-04-23T17:02:41.308Z"
        "eventName" =&gt; "ObjectCreated:Put"
        "userIdentity" =&gt; array:1 [
          "principalId" =&gt; "AWS:XXXXXXXXXXXXXXXXXX"
        ]
        "requestParameters" =&gt; array:1 [
          "sourceIPAddress" =&gt; "217.64.198.7"
        ]
        "responseElements" =&gt; array:2 [
          "x-amz-request-id" =&gt; "602CE18B8DE0BE5C"
          "x-amz-id-2" =&gt; "wA/A3Jl2XpoxBWJEgQzy11s6O28Cz9Wc6pVi6Ho1vnIrOjqsWkGozlUmqRdpYAfub0MqdF8d/YI="
        ]
        "s3" =&gt; array:4 [
          "s3SchemaVersion" =&gt; "1.0"
          "configurationId" =&gt; "0d4eaa75-5730-495e-b6d4-368bf3690f30"
          "bucket" =&gt; array:3 [
            "name" =&gt; "mybucket"
            "ownerIdentity" =&gt; array:1 [
              "principalId" =&gt; "XXXXXXXXXXXXXXXXXX"
            ]
            "arn" =&gt; "arn:aws:s3:::mybucket"
          ]
          "object" =&gt; array:4 [
            "key" =&gt; "dirName/myFile.txt"
            "size" =&gt; 1991721
            "eTag" =&gt; "824a20edad0091027b5d0fa6d78bb24f"
            "sequencer" =&gt; "005CBF452E30AAC02A"
          ]
        ]
      ]
    ]
  ]
  </code></pre>
  
  <p>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 ?</p>