You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/appsync_events.md
+84-122
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,12 @@ stateDiagram-v2
57
57
58
58
You must have an existing AppSync Events API with real-time capabilities enabled and IAM permissions to invoke your Lambda function. That said, there are no additional permissions required to use Event Handler as routing requires no dependency (_standard library_).
AppSync Events uses a specific event format for Lambda requests and responses. In most scenarios, Powertools simplifies this interaction by automatically formatting resolver returns to match the expected AppSync response structure.
@@ -79,12 +85,13 @@ AppSync Events uses a specific event format for Lambda requests and responses. I
When processing events with Lambda, you can return errors to AppSync in two ways:
90
+
When processing events with Lambda, you can return errors to AppSync in three ways:
85
91
86
92
***Error per item:** Return an `error` key within each individual item's response. AppSync Events expects this format for item-specific errors.
87
93
***Fail entire request:** Return a JSON object with a top-level `error` key. This signals a general failure, and AppSync treats the entire request as unsuccessful.
94
+
***Unauthorized exception**: Raise the **UnauthorizedException** exception to reject a subscribe or publish request with HTTP 403.
88
95
89
96
### Resolver decorator
90
97
@@ -129,21 +136,6 @@ When multiple handlers could match the same event, the most specific pattern tak
129
136
130
137
More specific routes will always take precedence over less specific ones. For example, `/default/channel1` will take precedence over `/default/*`, which will take precedence over `/*`.
131
138
132
-
### Processing events with async resolvers
133
-
134
-
Use the `@app.async_on_publish()` decorator to process events asynchronously.
135
-
136
-
We use `asyncio` module to support async functions, and we ensure reliable execution by managing the event loop.
137
-
138
-
???+ note "Events order and AppSync Events"
139
-
AppSync does not rely on event order. As long as each event includes the original `id`, AppSync processes them correctly regardless of the order in which they are received.
@@ -165,11 +157,27 @@ You can enable this with the `aggregate` parameter:
165
157
166
158
### Handling errors
167
159
168
-
You can filter or reject events by raising exceptions in your handlers. The event handler will catch these exceptions and include appropriate error information in the response.
160
+
You can filter or reject events by throwing exceptions in your resolvers or by formatting the payload according to the expected response structure. This instructs AppSync not to propagate that specific message, so subscribers will not receive the corresponding message.
169
161
170
-
#### Error with individual itens
162
+
#### Handling errors with individual items
171
163
172
-
**Note:** When using `aggregate=True`, you are responsible for formatting the error response according to the expected format.
164
+
When processing items individually with `aggregate=False`, you can raise an exception to fail a specific item. When an exception is raised, the Event Handler will catch it and include the exception name and message in the response.
When processing batch of items with `aggregate=False`, you can must format the payload according the expected response.
173
181
174
182
=== "working_with_error_handling.py"
175
183
@@ -185,121 +193,75 @@ You can filter or reject events by raising exceptions in your handlers. The even
185
193
186
194
#### Rejecting the entire request
187
195
196
+
??? warning "Raising `UnauthorizedException` will cause the Lambda invocation to fail."
197
+
198
+
You can also reject the entire payload by raising an `UnauthorizedException`. This prevents Powertools from processing any messages and causes the Lambda invocation to fail, returning an error to AppSync.
Use the `@app.async_on_publish()` decorator to process events asynchronously.
215
+
216
+
We use `asyncio` module to support async functions, and we ensure reliable execution by managing the event loop.
217
+
218
+
???+ note "Events order and AppSync Events"
219
+
AppSync does not rely on event order. As long as each event includes the original `id`, AppSync processes them correctly regardless of the order in which they are received.
0 commit comments