Link to chapter — https://serverless-stack.com/chapters/add-an-api-to-create-a-note.html
When I test the API following the code, the response is Failed to load resource: the server responded with a status of 404 ()
.
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"content":"Hello World","attachment":"hello.jpg"}' \
https://5bv7x0iuga.execute-api.us-east-1.amazonaws.com/notes
Are you using the URL from your API? The one in the screenshot is from the example we have in the chapter.
Yes. I use from my API.
Hmm can you try running sst start
again? It seems like maybe the route wasn’t deployed.
I do npx sst start
. And the response is like this…
HTTP/1.1 404 Not Found
Date: Tue, 31 Aug 2021 00:34:36 GMT
Content-Type: application/json
Content-Length: 23
Connection: close
apigw-requestid: E5_caiI2NjMEMUQ=
{
"message": "Not Found"
}
Also I tried previous hello world too. And response was
Hello, World! Your request was received at 31/Aug/2021:00:59:44 +0000.
.
Hmm can you share a GitHub repo with your app? I can take a look.
Thank you so much…!!
Hmm you might’ve missed the Adding to the App step in the chapter? Your lib/index.js
isn’t adding the ApiStack
.
- index.js
import StorageStack from "./StorageStack";
import ApiStack from "./ApiStack";
export default function main(app) {
const storageStack = new StorageStack(app, "storage");
new ApiStack(app, "api", {
table: storageStack.table,
});
}
Hmm… I recreated iam user from another AWS account and tried again. But it’s still error:404. So I guess it’s not a problem of account.
I recreated note app. And hello world was statusCode: 200 in terminal like your terminal. But when I move to test the API with curl -X POST \
, Again {"message":"Not Found"}
and error: 404…
I deleted the file. And I pulled from the repository and fixed what you mentioned. But the hello world have 404 error and {"message":"Not Found"}
.
Failed to load resource: the server responded with a status of 404 ()
I did curl -X POST \ -v
. And the response:
* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 404
< date: Tue, 31 Aug 2021 07:36:23 GMT
< content-type: application/json
< content-length: 23
< apigw-requestid: E69Oqg1wtjMEMBw=
<
* Connection #0 to host p57ypgdxgf.execute-api.ap-northeast-1.amazonaws.com left intact
{"message":"Not Found"}* Closing connection 0
Also I took a loom. So it would be helpful, if you could check it out. Loom | Free Screen & Video Recording Software
We remove the Hello World API in this chapter. So it shouldn’t work anymore.
But the URL in your Loom video is missing /notes
at the end.
Ohh… /notes
at the end. I got it. Thank you so much
If you’re running the following on the windows platform
curl -X POST -H ‘Content-Type: application/json’ -d ‘{“content”:“Hello World”,“attachment”:“hello.jpg”}’ https://yourendpoint.amazonaws.com/notes
And messages/errors are returned
- Unnecessary use of -X or --request, POST is already inferred.
- Could not resolve host: application
- {“message”:“Internal Server Error”}
Apply the following resolution
- Optionally drop the -X POST switch
- Replace sgl-quotes w/ dbl-quotes
- Escape the dbl-quotes surrounding the NVPs inside the {JSON}
Example
curl -H “Content-Type: application/json” -d “{\“content\”:\“Hello World\”,\“attachment\”:\“hello.jpg\”}” https://yourendpoint.amazonaws.com/notes
Just began the SST tutorial, encountered the above, and sharing for anyone new like me.
Since adding the storage and api stacks I have noticed the the “my-stack” stack is still hanging around. What’s the recommended way to manage these dangling stacks? I could go to the console and manually delete them I supposed, but that feels cumbersome.
Hmm that’s not right. Can you try doing a full npx sst deploy
?
I just ran npx sst deploy
and am still seeing the “my-stack” stack. It’s possible I could’ve missed something while working through the beginning of the guide. These are the stacks I see in my console:
- dev-sst-notes-debug-stack
- dev-sst-notes-my-stack
- dev-sst-notes-storage
- dev-sst-notes-api
I would expect all but the dev-sst-notes-my-stack
stack to exist.
What do you think?
Update:
I also ran npm sst deploy --stage prod
and am still seeing the prod-sst-notes-my-stack
stack.