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

[docs] Update create-a-dynamodb-table-in-sst.md #724

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions _chapters/add-an-api-to-create-a-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We'll first add an API to create a note. This API will take the note object as t

### Creating a Stack

{%change%} Create a new file in `stacks/ApiStack.js` and add the following.
{%change%} Create a new file in `stacks/ApiStack.ts` and add the following.

```js
import { Api, use } from "sst/constructs";
Expand Down Expand Up @@ -83,7 +83,7 @@ stacks(app) {

Now let's add the function that'll be creating our note.

{%change%} Create a new file in `packages/functions/src/create.js` with the following.
{%change%} Create a new file in `packages/functions/src/create.ts` with the following.

```js
import * as uuid from "uuid";
Expand Down Expand Up @@ -194,7 +194,7 @@ Make a note of the `noteId`. We are going to use this newly created note in the

Before we move on to the next chapter, let's quickly refactor the code since we are going to be doing much of the same for all of our APIs.

{%change%} Start by replacing our `create.js` with the following.
{%change%} Start by replacing our `create.ts` with the following.

```js
import { Table } from "sst/node/table";
Expand Down Expand Up @@ -231,7 +231,7 @@ This code doesn't work just yet but it shows you what we want to accomplish:

Let's start by creating a `dynamodb` util that we can share across all our functions. We'll place this in the `packages/core` directory. This is where we'll be putting all our business logic.

{%change%} Create a `packages/core/src/dynamodb.js` file with:
{%change%} Create a `packages/core/src/dynamodb.ts` file with:

```js
import AWS from "aws-sdk";
Expand All @@ -249,7 +249,7 @@ export default {

Here we are creating a convenience object that exposes the DynamoDB client methods that we are going to need in this guide.

{%change%} Also create a `packages/core/src/handler.js` file with the following.
{%change%} Also create a `packages/core/src/handler.ts` file with the following.

```js
export default function handler(lambda) {
Expand Down Expand Up @@ -283,7 +283,7 @@ Let's go over this in detail.
- On success, we `JSON.stringify` the result and return it with a `200` status code.
- If there is an error then we return the error message with a `500` status code.

It's **important to note** that the `handler.js` needs to be **imported before we import anything else**. This is because we'll be adding some error handling to it later that needs to be initialized when our Lambda function is first invoked.
It's **important to note** that the `handler.ts` needs to be **imported before we import anything else**. This is because we'll be adding some error handling to it later that needs to be initialized when our Lambda function is first invoked.

Next, we are going to add the API to get a note given its id.

Expand All @@ -293,7 +293,7 @@ Next, we are going to add the API to get a note given its id.

- Response `statusCode: 500`

If you see a `statusCode: 500` response when you invoke your function, the error has been reported by our code in the `catch` block. You'll see a `console.error` is included in our `handler.js` code above. Incorporating logs like these can help give you insight on issues and how to resolve them.
If you see a `statusCode: 500` response when you invoke your function, the error has been reported by our code in the `catch` block. You'll see a `console.error` is included in our `handler.ts` code above. Incorporating logs like these can help give you insight on issues and how to resolve them.

```js
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions _chapters/create-a-dynamodb-table-in-sst.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We are now going to start creating our infrastructure in [SST]({{ site.sst_githu

### Create a Stack

{%change%} Add the following to a new file in `stacks/StorageStack.js`.
{%change%} Add the following to a new file in `stacks/StorageStack.ts`.

```js
import { Table } from "sst/constructs";
Expand Down Expand Up @@ -81,7 +81,7 @@ This will take a minute to run.
{%change%} Also remove the template files.

```bash
$ rm stacks/MyStack.ts packages/core/src/time.ts packages/functions/src/lambda.ts
$ rm stacks/MyStack.ts packages/functions/src/lambda.ts
```

### Add to the App
Expand Down