Skip to content

fix: Allow custom Lambda events from SQS#194

Merged
taylorotwell merged 5 commits into2.0from
fix-custom-lambda-events-from-sqs
Sep 10, 2025
Merged

fix: Allow custom Lambda events from SQS#194
taylorotwell merged 5 commits into2.0from
fix-custom-lambda-events-from-sqs

Conversation

@mathiasgrimm
Copy link
Contributor

@mathiasgrimm mathiasgrimm commented Sep 8, 2025

When sending Lambda events from SQS to Vapor, it would always handle it as a Vapor Job as it only checked for the messageId in the event data, however, a Vapor Job also has always a body->job attribute. This way, we can safely send custom Lambda events from SQS.

Before this fix, sending a custom event from SQS would cause the following:

  {
    "exception":{
      "class":"ErrorException",
      "message":"Undefined array key \"job\"",
      "code":0,
      "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:356",
      "previous":{
        "class":"ErrorException",
        "message":"Undefined array key \"job\"",
        "code":0,
        "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:251"
      }
    },
    "aws_request_id":"d88e2bb2-57ca-58e4-ae6b-4a8b65ea151f"
  }

In addition to the main fix, I've also renamed a test fixture for clarity: lambdaEvent.jsonjobLambdaEventFromSQS.json as it represents a SQS Job (it has both messageId and body->job). I've also added two other fixtures to represent SQS custom events and non-sqs custom events.

Lambda Custom Events was "documented" at https://blog.laravel.com/vapor-trigger-the-cli-lambda-using-custom-events#:~:text=To%20extract%20the%20event%20payload%20from%20the,image%20is%20uploaded%20to%20an%20S3%20bucket

CleanShot 2025-09-08 at 17 19 28@2x

CleanShot 2025-09-08 at 17 19 04@2x

mathiasgrimm and others added 2 commits September 8, 2025 17:43
When sending Lambda events from SQS to Vapor, it would always handle it as a Vapor Job as it only checked for the `messageId` in the event data, however, a Vapor Job also has always a `body->job` attribute as well. This way we can safely send custom Lambda events from SQS.

Before this fix, sending a custom event from SQS would cause the following:

```
  {
    "exception":{
      "class":"ErrorException",
      "message":"Undefined array key \"job\"",
      "code":0,
      "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:356",
      "previous":{
        "class":"ErrorException",
        "message":"Undefined array key \"job\"",
        "code":0,
        "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:251"
      }
    },
    "aws_request_id":"d88e2bb2-57ca-58e4-ae6b-4a8b65ea151f"
  }
```

 In addition to the main fix, I've also renamed a test fixture for clarity: `lambdaEvent.json` → `jobLambdaEventFromSQS.json` as it represents a SQS Job (it has both `messageId` and `body->job`). I've also added two other fixtures to represent SQS custom events and non-sqs custom events.

 Lambda Custom Events was "documented" at https://blog.laravel.com/vapor-trigger-the-cli-lambda-using-custom-events#:~:text=To%20extract%20the%20event%20payload%20from%20the,image%20is%20uploaded%20to%20an%20S3%20bucket
mathiasgrimm and others added 3 commits September 8, 2025 17:44
When sending Lambda events from SQS to Vapor, it would always handle it as a Vapor Job as it only checked for the `messageId` in the event data, however, a Vapor Job also has always a `body->job` attribute as well. This way we can safely send custom Lambda events from SQS.

Before this fix, sending a custom event from SQS would cause the following:

```
  {
    "exception":{
      "class":"ErrorException",
      "message":"Undefined array key \"job\"",
      "code":0,
      "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:356",
      "previous":{
        "class":"ErrorException",
        "message":"Undefined array key \"job\"",
        "code":0,
        "file":"/var/task/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:251"
      }
    },
    "aws_request_id":"d88e2bb2-57ca-58e4-ae6b-4a8b65ea151f"
  }
```

 In addition to the main fix, I've also renamed a test fixture for clarity: `lambdaEvent.json` → `jobLambdaEventFromSQS.json` as it represents a SQS Job (it has both `messageId` and `body->job`). I've also added two other fixtures to represent SQS custom events and non-sqs custom events.

 Lambda Custom Events was "documented" at https://blog.laravel.com/vapor-trigger-the-cli-lambda-using-custom-events#:~:text=To%20extract%20the%20event%20payload%20from%20the,image%20is%20uploaded%20to%20an%20S3%20bucket
@taylorotwell taylorotwell merged commit 80faabf into 2.0 Sep 10, 2025
3 checks passed
@taylorotwell taylorotwell deleted the fix-custom-lambda-events-from-sqs branch September 10, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants