Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Sep 24, 2021
2 parents 1ccde9b + f3507cf commit 325e346
Show file tree
Hide file tree
Showing 51 changed files with 139 additions and 139 deletions.
4 changes: 2 additions & 2 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 `lib/ApiStack.js` and add the following.
{%change%} Create a new file in `stacks/ApiStack.js` and add the following.

``` js
import * as sst from "@serverless-stack/resources";
Expand Down Expand Up @@ -72,7 +72,7 @@ We are doing a couple of things of note here.
Let's add this new stack to the rest of our app.


{%change%} In `lib/index.js`, import the API stack at the top.
{%change%} In `stacks/index.js`, import the API stack at the top.

``` js
import ApiStack from "./ApiStack";
Expand Down
2 changes: 1 addition & 1 deletion _chapters/add-an-api-to-delete-a-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This makes a DynamoDB `delete` call with the `userId` & `noteId` key to delete t

Let's add a new route for the delete note API.

{%change%} Add the following below the `PUT /notes{id}` route in `lib/ApiStack.js`.
{%change%} Add the following below the `PUT /notes{id}` route in `stacks/ApiStack.js`.

``` js
"DELETE /notes/{id}": "src/delete.main",
Expand Down
2 changes: 1 addition & 1 deletion _chapters/add-an-api-to-get-a-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This follows exactly the same structure as our previous `create.js` function. Th

Let's add a new route for the get note API.

{%change%} Add the following below the `POST /notes` route in `lib/ApiStack.js`.
{%change%} Add the following below the `POST /notes` route in `stacks/ApiStack.js`.

``` js
"GET /notes/{id}": "src/get.main",
Expand Down
2 changes: 1 addition & 1 deletion _chapters/add-an-api-to-handle-billing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Clearly, our serverless infrastructure might be cheap but our service isn't!

Let's add a new route for our billing API.

{%change%} Add the following below the `DELETE /notes/{id}` route in `lib/ApiStack.js`.
{%change%} Add the following below the `DELETE /notes/{id}` route in `stacks/ApiStack.js`.

``` js
"POST /billing": "src/billing.main",
Expand Down
2 changes: 1 addition & 1 deletion _chapters/add-an-api-to-list-all-the-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This is pretty much the same as our `get.js` except we use a condition to only r

Let's add the route for this new endpoint.

{%change%} Add the following above the `POST /notes` route in `lib/ApiStack.js`.
{%change%} Add the following above the `POST /notes` route in `stacks/ApiStack.js`.

``` js
"GET /notes": "src/list.main",
Expand Down
2 changes: 1 addition & 1 deletion _chapters/add-an-api-to-update-a-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ This should look similar to the `create.js` function. Here we make an `update` D

Let's add a new route for the get note API.

{%change%} Add the following below the `GET /notes/{id}` route in `lib/ApiStack.js`.
{%change%} Add the following below the `GET /notes/{id}` route in `stacks/ApiStack.js`.

``` js
"PUT /notes/{id}": "src/update.main",
Expand Down
6 changes: 3 additions & 3 deletions _chapters/adding-auth-to-our-serverless-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Setting this all up can be pretty complicated in CDK. SST has a simple [`Auth`](

### Create a Stack

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

``` js
import * as iam from "@aws-cdk/aws-iam";
Expand Down Expand Up @@ -115,7 +115,7 @@ One other thing to note is that, the federated identity id is a UUID that is ass

Let's add this stack to our app.

{%change%} Replace the `main` function in `lib/index.js` with this.
{%change%} Replace the `main` function in `stacks/index.js` with this.

``` js
export default function main(app) {
Expand Down Expand Up @@ -144,7 +144,7 @@ import AuthStack from "./AuthStack";

We also need to enable authentication in our API.

{%change%} Add the following above the `defaultFunctionProps: {` line in `lib/ApiStack.js`.
{%change%} Add the following above the `defaultFunctionProps: {` line in `stacks/ApiStack.js`.

``` js
defaultAuthorizationType: "AWS_IAM",
Expand Down
2 changes: 1 addition & 1 deletion _chapters/auth-in-serverless-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For reference, here is what we have so far.

Our users make a request to our serverless API. It starts by hitting our API Gateway endpoint. And depending on the endpoint we request, it'll forward that request to the appropriate Lambda function.

In terms of access control, our API Gateway endpoint is allowed to invoke the Lambda functions we listed in the routes of our `lib/ApiStack.js`. And if you'll recall, our Lambda function are allowed to connect to our DynamoDB tables.
In terms of access control, our API Gateway endpoint is allowed to invoke the Lambda functions we listed in the routes of our `stacks/ApiStack.js`. And if you'll recall, our Lambda function are allowed to connect to our DynamoDB tables.

``` js
// Allow the API to access the table
Expand Down
8 changes: 4 additions & 4 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 `lib/StorageStack.js`.
{%change%} Add the following to a new file in `stacks/StorageStack.js`.

``` js
import * as sst from "@serverless-stack/resources";
Expand Down Expand Up @@ -69,7 +69,7 @@ This'll allow us to reference this resource in our other stacks.

Now let's add this stack to our app.

{%change%} Replace the `lib/index.js` with this.
{%change%} Replace the `stacks/index.js` with this.

``` js
import StorageStack from "./StorageStack";
Expand All @@ -92,7 +92,7 @@ Stack dev-notes-storage
Status: deployed
```

The `Stack` name above of `dev-notes-storage` is a string derived from your `${stageName}-${appName}-${stackName}`. Your `appName` is defined in the `name` field of your `sst.json` file and your `stackName` is the label you choose for your stack in `lib/index.js'.
The `Stack` name above of `dev-notes-storage` is a string derived from your `${stageName}-${appName}-${stackName}`. Your `appName` is defined in the `name` field of your `sst.json` file and your `stackName` is the label you choose for your stack in `stacks/index.js'.

### Remove Template Files

Expand All @@ -101,7 +101,7 @@ There are a couple of files that came with our starter template, that we can now
{%change%} Run the following in your project root.

``` bash
$ rm lib/MyStack.js src/lambda.js
$ rm stacks/MyStack.js src/lambda.js
```

Now that our database has been created, let's create an S3 bucket to handle file uploads.
2 changes: 1 addition & 1 deletion _chapters/create-a-hello-world-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ comments_id: create-a-hello-world-api/2460

With our newly created [SST]({{ site.sst_github_repo }}) app, we are ready to deploy a simple _Hello World_ API.

In `lib/MyStack.js` you'll notice a API definition similar to this.
In `stacks/MyStack.js` you'll notice a API definition similar to this.

``` js
export default class MyStack extends sst.Stack {
Expand Down
4 changes: 2 additions & 2 deletions _chapters/create-a-new-reactjs-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Now to use this package, we'll add it to our `package.json` scripts.

We are going to be deploying our React app to AWS. To do that we'll be using the SST [`ReactStaticSite`](https://docs.serverless-stack.com/constructs/ReactStaticSite) construct.

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

``` js
import * as sst from "@serverless-stack/resources";
Expand Down Expand Up @@ -105,7 +105,7 @@ We are doing a couple of things of note here:

Let's add this new stack to the rest of our app.

{%change%} Replace the `main` function in `lib/index.js` with.
{%change%} Replace the `main` function in `stacks/index.js` with.

``` js
export default function main(app) {
Expand Down
4 changes: 2 additions & 2 deletions _chapters/create-an-s3-bucket-in-sst.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We'll be adding to the `StorageStack` that we created.

### Add to the Stack

{%change%} Add the following above the `sst.Table` definition in `lib/StorageStack.js`.
{%change%} Add the following above the `sst.Table` definition in `stacks/StorageStack.js`.

``` js
// Create an S3 bucket
Expand All @@ -24,7 +24,7 @@ this.bucket = new sst.Bucket(this, "Uploads");

This creates a new S3 bucket using the SST [`Bucket`](https://docs.serverless-stack.com/constructs/Bucket) construct.

Also, find the following line in `lib/StorageStack.js`.
Also, find the following line in `stacks/StorageStack.js`.

``` js
// Public reference to the table
Expand Down
4 changes: 2 additions & 2 deletions _chapters/create-an-sst-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ By default our app will be deployed to an environment (or stage) called `dev` in

An SST app is made up of two parts.

1. `lib/` — App Infrastructure
1. `stacks/` — App Infrastructure

The code that describes the infrastructure of your serverless app is placed in the `lib/` directory of your project. SST uses [AWS CDK]({% link _chapters/what-is-aws-cdk.md %}), to create the infrastructure.
The code that describes the infrastructure of your serverless app is placed in the `stacks/` directory of your project. SST uses [AWS CDK]({% link _chapters/what-is-aws-cdk.md %}), to create the infrastructure.

2. `src/` — App Code

Expand Down
6 changes: 3 additions & 3 deletions _chapters/custom-domains-for-react-apps-on-aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ comments_id: custom-domains-for-react-apps-on-aws/2463

In the [previous chapter we configured a custom domain for our serverless API]({% link _chapters/custom-domains-in-serverless-apis.md %}). Now let's do the same for our frontend React.js app.

{%change%} In the `lib/FrontendStack.js` add the following below the `new sst.ReactStaticSite(` line.
{%change%} In the `stacks/FrontendStack.js` add the following below the `new sst.ReactStaticSite(` line.

``` js
customDomain:
Expand All @@ -32,7 +32,7 @@ You won't need to set the `domainAlias` for the non-prod versions because we don

We need to use the custom domain URL of our API in our React app.

{%change%} Find the following line in `lib/FrontendStack.js`.
{%change%} Find the following line in `stacks/FrontendStack.js`.

``` js
REACT_APP_API_URL: api.url,
Expand All @@ -48,7 +48,7 @@ Note that, if you are going to use a custom domain locally, you might need to re

We also need to update the outputs of our frontend stack.

{%change%} Replace the `this.addOutputs` call at the bottom of `lib/FrontendStack.js` with this.
{%change%} Replace the `this.addOutputs` call at the bottom of `stacks/FrontendStack.js` with this.

``` js
this.addOutputs({
Expand Down
4 changes: 2 additions & 2 deletions _chapters/custom-domains-in-serverless-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ comments_id: custom-domains-in-serverless-apis/2464

In the [previous chapter]({% link _chapters/purchase-a-domain-with-route-53.md %}) we purchased a new domain on [Route 53](https://aws.amazon.com/route53/). Now let's use it for our serverless API.

{%change%} In your `lib/ApiStack.js` add the following above the `defaultAuthorizationType: "AWS_IAM",` line.
{%change%} In your `stacks/ApiStack.js` add the following above the `defaultAuthorizationType: "AWS_IAM",` line.

``` js
customDomain:
Expand All @@ -23,7 +23,7 @@ We could for example, base it on the stage name, `api-${scope.stage}.my-serverle

We also need to update the outputs of our API stack.

{%change%} Replace the `this.addOutputs` call at the bottom of `lib/ApiStack.js`.
{%change%} Replace the `this.addOutputs` call at the bottom of `stacks/ApiStack.js`.

``` js
this.addOutputs({
Expand Down
2 changes: 1 addition & 1 deletion _chapters/deploy-a-serverless-app-with-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The short version is that:

In our [resources repo]({{ site.backend_ext_resources_github_repo }}) we are using SST to deploy our CDK app. CDK internally keeps track of the dependencies between stacks.

Our `lib/index.js` looks like this.
Our `stacks/index.js` looks like this.

``` javascript
export default function main(app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ $ cd social-cards

The infrastructure in our app is defined using [CDK]({% link _chapters/what-is-aws-cdk.md %}). Currently we just have a simple API that invokes a Lambda function.

You can see this in `lib/MyStack.js`.
You can see this in `stacks/MyStack.js`.

``` js
// Create a HTTP API
Expand Down Expand Up @@ -174,7 +174,7 @@ The `encoded_title` is a [Base64 encoded](https://en.wikipedia.org/wiki/Base64)

We are going to use [Puppeteer](https://developers.google.com/web/tools/puppeteer) to take these screenshots. We'll be using [a publicly available Lambda Layer](https://github.com/shelfio/chrome-aws-lambda-layer) for it. It allows us to skip having to compile Puppeteer specifically for AWS Lambda.

So the API definition in `lib/MyStack.js` now looks like this.
So the API definition in `stacks/MyStack.js` now looks like this.

``` js
const api = new sst.Api(this, "Api", {
Expand Down Expand Up @@ -408,7 +408,7 @@ If we visit our API multiple times, it takes a screenshot every time. This is bo

First, we'll create our S3 bucket.

In `lib/MyStack.js` above our API definition we have.
In `stacks/MyStack.js` above our API definition we have.

``` js
// Create S3 bucket to store generated images
Expand Down Expand Up @@ -541,7 +541,7 @@ Now if you load your API endpoint a couple of times, you'll notice it is much fa

To make our requests even faster we'll add a CDN in front of our API. We'll use [CloudFront](https://aws.amazon.com/cloudfront/) for this.

In `lib/MyStack.js` we'll define our CloudFront distribution.
In `stacks/MyStack.js` we'll define our CloudFront distribution.

``` js
// Create CloudFront Distribution
Expand Down Expand Up @@ -582,7 +582,7 @@ If you are looking to create a new domain, you can [follow this guide to purchas

Or if you have a domain hosted on another provider, [read this to migrate it to Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html).

We can do this in our `lib/MyStack.js` by adding this block above the CloudFront definition.
We can do this in our `stacks/MyStack.js` by adding this block above the CloudFront definition.

``` js
const rootDomain = "serverless-stack.com";
Expand Down Expand Up @@ -640,7 +640,7 @@ if (useCustomDomain) {
}
```
Make sure to check out the full `lib/MyStack.js` source here — [{{ page.repo | remove: "https://" }}/blob/main/lib/MyStack.js]({{ page.repo }}/blob/main/lib/MyStack.js)
Make sure to check out the full `stacks/MyStack.js` source here — [{{ page.repo | remove: "https://" }}/blob/main/stacks/MyStack.js]({{ page.repo }}/blob/main/stacks/MyStack.js)
Now you can load our custom domain URL!
Expand Down
2 changes: 1 addition & 1 deletion _chapters/handle-cors-in-s3-for-file-uploads.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In the notes app we are building, users will be uploading files to the bucket we

Let's enable CORS for our S3 bucket.

{%change%} Replace the following line in `lib/StorageStack.js`.
{%change%} Replace the following line in `stacks/StorageStack.js`.

``` js
this.bucket = new sst.Bucket(this, "Uploads");
Expand Down
2 changes: 1 addition & 1 deletion _chapters/handling-secrets-in-sst.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Also, since we won't be committing this file to Git, we'll need to add this to o

Next, let's add these to our functions.

{%change%} Add the following below the `TABLE_NAME: table.tableName,` line in `lib/ApiStack.js`:
{%change%} Add the following below the `TABLE_NAME: table.tableName,` line in `stacks/ApiStack.js`:

``` js
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
Expand Down
4 changes: 2 additions & 2 deletions _chapters/parameterize-serverless-resources-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resources:
For CDK on the other hand we use [SST](https://github.com/serverless-stack/serverless-stack) to automatically parameterize our stack names. And use a helper method to parameterize specific resource names.
So for example in the `lib/index.js` file in our [resources repo]({{ site.backend_ext_resources_github_repo }}).
So for example in the `stacks/index.js` file in our [resources repo]({{ site.backend_ext_resources_github_repo }}).

``` javascript
export default function main(app) {
Expand All @@ -73,7 +73,7 @@ dev-notes-ext-infra-cognito

Where `dev` is the stage we are deploying to and `notes-ext-infra` is the name of our SST app, as specified in our `sst.json`.

For specific resources, such as CloudFormation exports, we use the `app.logicalPrefixedName` helper method. Here's an example from `lib/DynamoDBStack.js`.
For specific resources, such as CloudFormation exports, we use the `app.logicalPrefixedName` helper method. Here's an example from `stacks/DynamoDBStack.js`.

``` javascript
new CfnOutput(this, "TableName", {
Expand Down
2 changes: 1 addition & 1 deletion _chapters/unexpected-errors-in-lambda-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const main = handler(async (event) => {

Now we'll set our Lambda function to use the lowest memory allowed.

{%change%} Add the following below the `defaultFunctionProps: {` line in your `lib/ApiStack.js`.
{%change%} Add the following below the `defaultFunctionProps: {` line in your `stacks/ApiStack.js`.

``` js
memorySize: 128,
Expand Down
2 changes: 1 addition & 1 deletion _chapters/unit-tests-in-serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Let's start by writing a test for the CDK infrastructure in our app. We are goin
``` js
import { expect, haveResource } from "@aws-cdk/assert";
import * as sst from "@serverless-stack/resources";
import StorageStack from "../lib/StorageStack";
import StorageStack from "../stacks/StorageStack";

test("Test StorageStack", () => {
const app = new sst.App();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To understand this better we'll be referencing an example SST application on Git

This example SST app has a couple of key parts:

- **The `lib/` directory**: This contains the code that describes the infrastructure of your serverless app. It works by leveraging [AWS CDK](https://serverless-stack.com/chapters/what-is-aws-cdk.html) to create the infrastructure. This includes our API, our Cognito services, and our frontend static site.
- **The `stacks/` directory**: This contains the code that describes the infrastructure of your serverless app. It works by leveraging [AWS CDK](https://serverless-stack.com/chapters/what-is-aws-cdk.html) to create the infrastructure. This includes our API, our Cognito services, and our frontend static site.
- **The `src/` directory**: This is where the application code resides. The code that will run when your API is called.
- **The `frontend/` directory**: This is where our frontend React.js application is. It'll be connecting to our APIs.

Expand All @@ -43,7 +43,7 @@ Let’s start with looking at how to add Cognito User Pool to our app.

In the [previous chapter]({% link _chapters/how-to-add-authentication-to-a-serverless-app.md %}) we talked about the various parts of Cognito ([User Pools and Identity Pools]({% link _chapters/cognito-user-pool-vs-identity-pool.md %})).

SST makes it easy to add these to your application. In [`lib/MyStack.js`]({{ repo_url }}/lib/MyStack.js) you'll notice.
SST makes it easy to add these to your application. In [`stacks/MyStack.js`]({{ repo_url }}/stacks/MyStack.js) you'll notice.

``` js
// Create a Cognito User Pool to manage auth
Expand Down Expand Up @@ -112,7 +112,7 @@ new Auth(this, "Auth", {

### Adding an API

Now let's look at how we can use Cognito to secure our API. In [`lib/MyStack.js`]({{ repo_url }}/lib/MyStack.js) of our example, you'll notice our SST [`Api`](https://docs.serverless-stack.com/constructs/Api) definition.
Now let's look at how we can use Cognito to secure our API. In [`stacks/MyStack.js`]({{ repo_url }}/stacks/MyStack.js) of our example, you'll notice our SST [`Api`](https://docs.serverless-stack.com/constructs/Api) definition.

``` js
// Create an HTTP API
Expand Down Expand Up @@ -161,7 +161,7 @@ export async function handler() {

### Adding a React Static Site

We can now turn our attention to the frontend part of our application. In [`lib/MyStack.js`]({{ repo_url }}/lib/MyStack.js) take a look at the SST [`ReactStaticSite`](https://docs.serverless-stack.com/constructs/ReactStaticSite) definition.
We can now turn our attention to the frontend part of our application. In [`stacks/MyStack.js`]({{ repo_url }}/stacks/MyStack.js) take a look at the SST [`ReactStaticSite`](https://docs.serverless-stack.com/constructs/ReactStaticSite) definition.

``` js
// Deploy our React app
Expand All @@ -187,7 +187,7 @@ The key here is that we are [setting the outputs from our backend as environment
4. Id of our Cognito Identity Pool
5. And the Id of the Cognito User Pool client

You can check out the rest of [`lib/MyStack.js`]({{ repo_url }}/lib/MyStack.js) for reference.
You can check out the rest of [`stacks/MyStack.js`]({{ repo_url }}/stacks/MyStack.js) for reference.

Now we are ready to create our React app.

Expand Down
Loading

0 comments on commit 325e346

Please sign in to comment.