Can't run all the different endpoints successfully
I was able to:
- list all the todo items
- create a todo item
However, I got 5xx errors when doing at least:
- update a todo item
- delete a todo item
- show a todo item (don't remember if I did or not)
I think the documentation might be old, as the curl commands don't work out-of-the-box after replacing the placeholder id with the actual id. So I used Postman instead, which included the application/json in the header and it worked for listing todos and creating todos.
It seems like the resources are provisioned correctly since todo items are stored and retrieved from dynamodb. However, the other ones wouldn't.
What could be the reason?
Hi @Michael-Xie , I think I've experienced more-or-less the same thing as you.
if you run localstack in DEBUG mode:
DEBUG=1 localstack start
and then attempt to delete a Todo you should see:
2023-08-01T20:34:24.573 WARN --- [ asgi_gw_3] l.s.apigateway.integration : Lambda output should follow the next JSON format: { "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... },"body": "..."}
This is because the API Gateway / Lambda integration requires the responses which Lambdas return to conform to a particular format.. Adding a body attribute to the response dict should get it working for you, even an empty string.
delete.py
...
# create a response
response = {
"statusCode": 200,
"body": "" #<-- Add this
}
return response
For the update endpoint, there is some logic which checks that you are including 'checked' in your payload:
update.py
...
def update(event, context):
data = json.loads(event['body'])
if 'text' not in data or 'checked' not in data:
logging.error("Validation Failed")
raise Exception("Couldn't update the todo item.")
return
...
If you send a request like this:
PUT /restapis/<rest_api_id>/local/user_request/todos/
{"text":"foobar"}
The response will be a 502 error, because this simple example doesn't have proper error handling (see the reasons above), however if you look at your DEBUG logs:
`
[ERROR] 2023-08-01T20:51:13.436Z bdd13a46-753b-4938-8b77-f2c3fd8ee4a6 Validation Failed 2023-08-01T20:51:13.445 DEBUG --- [ asgi_gw_3] l.s.a.i.version_manager : > [ERROR] Exception: Couldn't update the todo item. 2023-08-01T20:51:13.445 DEBUG --- [ asgi_gw_3] l.s.a.i.version_manager : > Traceback (most recent call last): 2023-08-01T20:51:13.445 DEBUG --- [ asgi_gw_3] l.s.a.i.version_manager : > File "/var/task/todos/update.py", line 20, in update 2023-08-01T20:51:13.445 DEBUG --- [ asgi_gw_3] l.s.a.i.version_manager : > raise Exception("Couldn't update the todo item.") 2023-08-01T20:51:13.445 DEBUG --- [ asgi_gw_3] l.s.a.i.version_manager : > END RequestId: bdd13a46-753b-4938-8b77-f2c3fd8ee4a6 ` Updating my payload so that it looked like this:
PUT /restapis/<rest_api_id>/local/user_request/todos/
{"text":"foobar","checked":"true"}
...worked for me! I hope this helps!
Hi! We just wanted to follow up on our last message to see whether your issue has been resolved. Were you able to get it working with the latest version of LocalStack? We would appreciate your feedback!