Just like the previous chapter, we are going to be using AWS CDK in our SST app to create an S3 bucket.

We will be adding to the StorageStack that we created.

Add to the Stack

Change indicator Add the following inside the StorageStack function above the Table definition in stacks/StorageStack.ts.

// Create an S3 bucket
const bucket = new Bucket(stack, "Uploads");

Change indicator Make sure to import the Bucket construct by replacing the import line at the top with the line below.

import { Bucket, StackContext, Table } from "sst/constructs";

This creates a new S3 bucket using the SST Bucket construct.

Also, find the following line in stacks/StorageStack.ts.

return {
  table,
};

Change indicator And add the bucket above table matching the code below.

return {
    bucket,
    table,
};

This will allow us to reference the S3 bucket in other stacks.

Note, learn more about sharing resources between stacks here.

Deploy the App

If you switch over to your terminal, you will notice that your changes are being deployed.

Note that, you will need to have sst dev running for this to happen. If you had previously stopped it, then running pnpm sst dev will deploy your changes again.

You should see that the storage stack has been updated.

✓  Deployed:
   StorageStack

Commit the Changes

Change indicator Let’s commit and push our changes to GitHub.

$ git add .
$ git commit -m "Adding a storage stack"
$ git push

Next, let’s create the API for our notes app.