Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead letter queues #6033

Closed
eladb opened this issue Mar 21, 2024 · 11 comments · Fixed by #6060
Closed

Dead letter queues #6033

eladb opened this issue Mar 21, 2024 · 11 comments · Fixed by #6060
Assignees
Labels
✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl 🎨 sdk SDK

Comments

@eladb
Copy link
Contributor

eladb commented Mar 21, 2024

Use Case

I'd like to be able to specify dead letter queues in Wing for cloud.Functions and cloud.Queues.

Proposed Solution

bring cloud;

let deadLetters = new cloud.Queue();

new cloud.Function(inflight () => {}, dlq: deadLetters);
new cloud.Queue(dlq: deadLetters);

Implementation Notes

For AWS:

Component

SDK

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@eladb eladb added ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl labels Mar 21, 2024
@staycoolcall911
Copy link
Contributor

@Chriscbr - can you please share some guidelines?

@marciocadev
Copy link
Collaborator

I can pick up this one

@staycoolcall911
Copy link
Contributor

Amazing @marciocadev ! All yours

@ekeren
Copy link
Collaborator

ekeren commented Mar 25, 2024

Oh great @marciocadev , you just made my request to make sure it also works on awscdk much simpler

@garysassano
Copy link
Collaborator

Using a Lambda onFailure destination for implementing a DLQ in a Lambda function is a more advanced and recent approach, offering a significant improvement. This method provides a more detailed payload when an error occurs, simplifying the process of diagnosing issues. A concise video that explains the advantages of this technique can be found here.

@marciocadev
Copy link
Collaborator

no problem @garysassano

I can set the onFailure destination to send messages to dlq

@marciocadev
Copy link
Collaborator

  • dlq (with retries) for queue (tf-aws / awscdk)
  • dlq (with retries) for queue (sim)
  • dlq for function (tf-aws / awscdk)
  • dlq for function (sim)

@marciocadev
Copy link
Collaborator

Guys, it's only possible to add a dead-letter queue (DLQ) to a lambda if the event producer is an asynchronous resource (such as Topic, DynamoDB and Bucket events, EventBridge events, etc).

The lambda that consumes an event from a Queue, for example, cannot have a DLQ because SQS is a synchronous resource; it waits for a response from the function and handles accordingly. The API Gateway also faces the same issue.

I'm saying this because I don't think the example new cloud.Function(inflight () => {}, dlq: deadLetters); can work

In the case of Wing, I think the best example would be to add a DLQ to a lambda that consumes asynchronous resources such as Topic, Schedule, Bucket events, etc.

bring cloud;

let deadLetters = new cloud.Queue();
let topic = new cloud.Topic();

topic.onMessage(inflight(msg: str) => {...}, dlq: deadLetters);

@Chriscbr
Copy link
Contributor

Chriscbr commented Apr 1, 2024

That's a good callout @marciocadev - yeah, I'm not sure if the suggested API for adding DLQs on cloud.Function would be appropriate for the Wing SDK if it only works in combination with specific producers and if it only works on AWS.

Dead letter queues for cloud.Queue should be possible to support across other clouds (see https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues and https://cloud.google.com/pubsub/docs/handling-failures) so adding it to the Wing SDK surface area sounds like a more safe bet to me. @ekeren @eladb Do you know if this would serve the use cases you had in mind?

If we want to support AWS specific features / aren't sure if the design work to support this across other clouds is needed right now, it's possible we could first incubate some of these capabilities through AWS classes and methods, e.g.

let topic = new cloud.Topic();
let deadLetters = new cloud.Queue();
if let topic = aws.Topic.from(topic) {
  topic.onMessage(inflight(msg: str) => {...}, dlq: deadLetters);
}

@marciocadev
Copy link
Collaborator

Maybe we can add support to function dlqs in a winglib, that way we can define as specific for aws

@mergify mergify bot closed this as completed in #6060 Apr 20, 2024
mergify bot pushed a commit that referenced this issue Apr 20, 2024
⛔ As the dead-letter queue linked to the function is a specific case of AWS, I will remove it from the scope of this PR.

- [x] dlq (with retries) for queue (tf-aws / awscdk)
- [x] dlq (with retries) for queue (sim)
~dlq for function (tf-aws / awscdk)~
~dlq for function (sim)~

Closes #6033

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.71.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl 🎨 sdk SDK
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants