https://serverless-stack.com/ logo
#help
Title
# help
m

manitej

06/11/2022, 2:28 PM
I don't think it's a bug, local and prod creates 2 different tables.
e

Eric

06/11/2022, 2:31 PM
both my local and prod have data in the table I'm pulling from
m

manitej

06/11/2022, 2:36 PM
I don't think so, can you show how are you passing the table name to the lambda?
I've confirmed that the dynamo db table is populated in both environments
m

manitej

06/11/2022, 2:40 PM
yeah , the above code creates a different table for each stage.
e

Eric

06/11/2022, 2:40 PM
and the GET /restaurants endpoint returns data in the SST console for local no problem
m

manitej

06/11/2022, 2:41 PM
local and prod tables won't share the data
try to insert data into the prod table and do a GET request.
e

Eric

06/11/2022, 2:42 PM
I did. the last screenshot in the thread is what I get and is my issue:
j

Jan Nylund

06/11/2022, 3:32 PM
Did you confirm dynamodb has content? (directly in aws console)
e

Eric

06/11/2022, 3:34 PM
yeah
a

Adrian Schweizer

06/11/2022, 10:13 PM
can you show the lambda code?
often, when I had a problem with local working prod not working, it was because I forgot to wait for a promise resolution in the handler code
lambda will kill your handler even with outstanding promises if it reaches the end of the function
not sure if it will still return a 200 OK then, but might be
yeah, it won't kill your handler, but I guess you know what I mean
actually forget the whole thing, it can't really be your problem here, my cases usually had to do with external services not being called, not a response not containing the expected results
but seeing your code might still help
e

Eric

06/13/2022, 12:29 PM
@Adrian Schweizer
a

Adrian Schweizer

06/13/2022, 3:00 PM
looks pretty normal
can you log results and check it out in cloudwatch
just
console.log(results)
should work i think
maybe put another console log with a fixed string above it so you know its not just null or something
e

Eric

06/13/2022, 11:34 PM
good suggestion to add console logging and checking cloud watch
I confirmed the prod stage Lambda is able to generate the response
however, this is what I get in the SST console...
very frustrating 😕
thanks for your assistance @Adrian Schweizer
finally got it working...
the response format from Lambda needs to be a certain way for API GW to return it
f

Frank

06/14/2022, 2:58 AM
@Eric glad u figured it out. Did you get it to work by changing
data
to
body
in the response?
e

Eric

06/14/2022, 12:00 PM
I just returned the
results.Items
from Dynamo DB and API GW set that return as the value for
body
j

Jay

06/16/2022, 9:58 PM
@Eric just to clarify here, was the issue that the response you were seeing in the SST Console was from the Lambda function, as opposed to the API GW response?
e

Eric

06/16/2022, 10:01 PM
@Jay, yeah...I think that ends up being the root cause. API GW expects a specific response format from the Lambda where the SST console does not. So my Lambda return format was working fine within the SST console but trying to get the response anywhere else didn't work since API GW wasn't processing the response correctly.
j

Jay

06/16/2022, 10:03 PM
Yeah I can see that being confusing. Because the Console is showing it as if the API returned that response but it didn't really.
e

Eric

06/16/2022, 10:04 PM
Agreed! Would be good to have some mention of that in the SST docs. Thanks for reaching out 🙂
a

Adrian Schweizer

06/17/2022, 11:09 AM
Ah, damn, how could I miss the data attribute in your code...sorry about that.