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

feat(docs): improve hosting with AWS Amplify document #10906

Merged
merged 17 commits into from Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion docs/docs/deploying-and-hosting.md
Expand Up @@ -5,6 +5,6 @@ overview: true

Getting your shiny new Gatsby site onto the cloud is probably the first thing you will want to do now that it's built! Also, give yourself a pat on the back real quick for creating something new!

In this section you'll find answers to questions about dealing with app routes that aren't at the root of your domain with `path prefixes`, as well as how to deploy to countless hosting solutions such as [Netlify](https://www.netlify.com/), [Cloudfront](https://aws.amazon.com/cloudfront/), and [GitHub Pages](https://pages.github.com/). As well as what's necessary to make sure you're fully prepared for a deploy! 🚀
In this section you'll find answers to questions about dealing with app routes that aren't at the root of your domain with `path prefixes`, as well as how to deploy to countless hosting solutions such as [Netlify](https://www.netlify.com/), [AWS Amplify Console](https://console.amplify.aws), and [GitHub Pages](https://pages.github.com/). As well as what's necessary to make sure you're fully prepared for a deploy! 🚀

[[guidelist]]
118 changes: 16 additions & 102 deletions docs/docs/deploying-to-s3-cloudfront.md
@@ -1,124 +1,38 @@
---
title: Deploying to S3/Cloudfront
title: Deploying to AWS Amplify
---

In this guide, we'll walk through how to host & publish your next Gatsby site to AWS using [AWS Amplify](https://aws-amplify.github.io/).
In this guide we'll walkthrough how to deploy and host your Gatsby site using the [AWS Amplify Console](https://console.amplify.aws).

AWS Amplify is a combination of client library, CLI toolchain, and UI components. Amplify allow developers to get up & running with full-stack cloud-powered applications with features like authentication, GraphQL, storage, REST APIs, analytics, Lambda functions, hosting & more.
AWS Amplify is a combination of client library, CLI toolchain, and a Console for continuous deployment and hosting. The Amplify CLI and library allow developers to get up & running with full-stack cloud-powered applications with features like authentication, storage, serverless GraphQL or REST APIs, analytics, Lambda functions, & more. The Amplify Console provides continuous deployment and hosting for modern web apps (single page apps and static site generators). Continuous deployment allows developers to deploy updates to their web app on every code commit to their Git repository. Hosting includes features such as globally available CDNs, easy custom domain setup + HTTPS, feature branch deployments, and password protection.

Using the **Hosting** feature, you can deploy your application to AWS as well as set up your site with Amazon Cloudfront CDN. This is what we'll be doing in this tutorial. Let's begin!

## Getting Started - Gatsby
## Pre-requisites

First, we'll want to create a new Gatsby project. If you don't already have Gatsby installed, install it:

```shell
npm install --global gatsby-cli
```
1. [Sign up for an AWS Account](https://portal.aws.amazon.com/billing/signup?redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation). There are no upfront charges or any term commitments to create an AWS account and signing up gives you immediate access to the AWS Free Tier

Next, we'll create a new Gatsby site:
1. This guide assumes that you have setup a Gatsby project. If you need to set up a project, start with the [Gatsby Auth starter with AWS Amplify](https://github.com/dabit3/gatsby-auth-starter-aws-amplify) then come back. The starter implements a basic authentication flow for signing up signing in users as well as protected client side routing.

```shell
gatsby new my-gatsby-site
```
![Gatsby Amplify](./images/amplify-gatsby-auth.gif)

Finally, change into the new site directory:

```shell
cd my-gatsby-site
```

## Getting Started - AWS Amplify
## Deployment

Now that we have our Gatsby site up & running, let's add hosting & make the site live on AWS.
1. Log in to the [AWS Amplify Console](https://console.aws.amazon.com/amplify/home) and choose Get Started under Deploy.
![Gatsby Amplify2](./images/amplify-gettingstarted.png)

First, we'll install the AWS Amplify CLI:
2. Connect a branch from your GitHub, Bitbucket, GitLab, or AWS CodeCommit repository. Connecting your repository allows Amplify to deploy updates on every code commit to a branch.
![Gatsby Amplify2](./images/amplify-connect-repo.gif)

```shell
npm i -g @aws-amplify/cli
```
3. Accept the default build settings. Give the Amplify Console permission to deploy backend resources with your frontend with a service role. This allows the Console to detect changes to both your backend and frontend on every code commit and make updates. If you do not have a service role follow the prompts to create one, then come back to the console and pick it from the dropdown.
![Gatsby Amplify2](./images/amplify-build-settings.gif)

With the AWS Amplify CLI installed, we now need to configure it with an IAM User:

```shell
amplify configure
```

> For a video walkthrough of how to configure the AWS Amplify CLI, click [here](https://www.youtube.com/watch?v=fWbM5DLh25U).

Now, we can create a new Amplify project in the root of our Gatsby project:

```shell
amplify init
```

- Choose your default editor: **(for me, this is Visual Studio Code)**
- Please choose the type of app that you're building: **javascript**
- What JavaScript framework are you using: **react**
- Source Directory Path: **src**
- Distribution Directory Path: **public**
- Build Command: **npm run-script build**
- Start Command: **npm run-script develop**
- Do you want to use an AWS profile? **Y**
- Please choose the profile you want to use: **default**

Now, the Amplify project has been created. You will see that you have a new amplify folder in your project directory as well as an .amplifyrc file. Both of these contain your AWS Amplify project configuration.

Next, we can type amplify into our command line & see all of the options that we have:

```shell
amplify
```

At the bottom, we can see the available categories available to us. Hosting is the category we would like to enable, so let's do so now:

```shell
amplify add hosting
```

Here, we'll be prompted for the following:

- Select the environment setup: **DEV**
- hosting bucket name: **gatsbyproj-20180808112129-hosting-bucket (or type whatever you'd like the bucket name to be)**

This will set up our local project with everything we need, now we can publish the app to AWS. To do so, we'll run the following command:

```shell
amplify publish
```

Here, we'll be prompted for the following:

- Are you sure you want to continue? **Y**

Now, our resources will be pushed up to our account & our site will be published to a live url!

What just happened? A few things:

1. Amplify runs npm run build to build a new distribution of your app
2. A new S3 bucket is created in your AWS account
3. All code in the public directory is uploaded to the S3 bucket

We should have also be given the URL that the site is hosted on. At any time that we would like to get the url for our site, we can run:

```shell
amplify status
```

This command should give us all of the info about our app including the url of our website.

If we ever want to configure the hosting setup, including adding Cloudfront, we can run:

```shell
amplify configure hosting
```

Here, we'll be prompted for what we would like to change about the project configuration.

> To learn more about AWS Amplify, check out the [Getting Started](https://aws-amplify.github.io/media/get_started) page.
4. Review your changes and then choose **Save and deploy**. The Amplify Console will pull code from your repository, build changes to the backend and frontend, and deploy your build artifacts at `https://master.unique-id.amplifyapp.com`. Bonus: Screenshots of your app on different devices to find layout issues :fire:
![Gatsby Amplify2](./images/amplify-gatsby-deploy.gif)

## References:

- [Publishing Your Next Gatsby Site to AWS With AWS Amplify](https://www.gatsbyjs.org/blog/2018-08-24-gatsby-aws-hosting/)
- [Escalade Sports: From $5000 to $5/month in Hosting With Gatsby](https://www.gatsbyjs.org/blog/2018-06-14-escalade-sports-from-5000-to-5-in-hosting/)
- [Deploy your Gatsby.js Site to AWS S3](https://benenewton.com/deploy-your-gatsby-js-site-to-aws-s-3)
Binary file added docs/docs/images/amplify-build-settings.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/amplify-connect-repo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/amplify-gatsby-auth.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/amplify-gatsby-deploy.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/amplify-gettingstarted.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion www/src/data/sidebars/doc-links.yaml
Expand Up @@ -22,7 +22,7 @@
items:
- title: Preparing your site for deployment*
link: /docs/preparing-for-deployment/
- title: Deploying to S3 and CloudFront
- title: Hosting on AWS Amplify
link: /docs/deploying-to-s3-cloudfront
- title: Deploying to Aerobatic
link: /docs/deploying-to-aerobatic/
Expand Down