S3

Static files and assets will be stored on S3.

The first thing we have to do is to build the React app.

$ cd packages/web
$ yarn build
Creating an optimized production build...
Compiled successfully.
...
✨  Done in 20.37s.

We now have a build folder:

build
├── asset-manifest.json
├── favicon.ico
├── index.html
├── manifest.json
├── precache-manifest.cdaef9d20bdd2939b5087486a61c7d6a.js
├── robots.txt
├── service-worker.js
└── static
    └── js
        ├── 0.b9fba7db.chunk.js
        ├── 0.b9fba7db.chunk.js.map
        ├── 3.b4b93fe8.chunk.js
        ├── 3.b4b93fe8.chunk.js.map
        ├── 4.d21e26c5.chunk.js
        ├── 4.d21e26c5.chunk.js.map
        ├── 5.bc17229d.chunk.js
        ├── 5.bc17229d.chunk.js.map
        ├── 6.0d642d4a.chunk.js
        ├── 6.0d642d4a.chunk.js.map
        ├── main.cb6ee362.chunk.js
        ├── main.cb6ee362.chunk.js.map
        ├── runtime-main.416359ae.js
        └── runtime-main.416359ae.js.map

Add build to .gitignore.

We are going to upload this to S3.

Creating a bucket

Search for S3 then click the Create bucket button.

  1. Follow the process, use the default values but untick Block all public access. (I like to name the bucket after the domain e.g daedalost.com)

  2. Once the bucket is created, click on it to see the details

  3. Go to Permission and paste the following:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::NAME_OF_BUCKET/*"
            ]
        }
    ]
}

Replace NAME_OF_BUCKET with your bucket's name.

Everyone on the internet can now access this bucket.

Later in the tutorial, we will use CloudFront to serve the assets from S3. Come back to this step and remove public access.

Have a look at the different Bucket Policy Examples from the AWS documentation.

Go to Properties > Static website hosting > Use this bucket to host a website:

  • Index document: index.html

  • Error document: index.html

This endpoint now serves the React app. It won't work at the moment since it doesn't connect to our API. Though, you can hard code http://localhost:8080 as the endpoint to test it locally.

Last updated

Was this helpful?