fix: Allow custom Lambda events from SQS#194
Merged
taylorotwell merged 5 commits into2.0from Sep 10, 2025
Merged
Conversation
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
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
…s' into fix-custom-lambda-events-from-sqs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When sending Lambda events from SQS to Vapor, it would always handle it as a Vapor Job as it only checked for the
messageIdin the event data, however, a Vapor Job also has always abody->jobattribute. This way, we can safely send custom Lambda events from SQS.Before this fix, sending a custom event from SQS would cause the following:
In addition to the main fix, I've also renamed a test fixture for clarity:
lambdaEvent.json→jobLambdaEventFromSQS.jsonas it represents a SQS Job (it has bothmessageIdandbody->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