layout | title | date | lang | description | comments_id | ref | redirect_from |
---|---|---|---|---|---|---|---|
post |
Deploy to S3 |
2017-02-06 16:00:00 -0800 |
en |
To use our React.js app in production we are going to use Create React App’s build command to create a production build of our app. And to upload our React.js app to an S3 Bucket on AWS, we are going to use the AWS CLI s3 sync command. |
deploy-to-s3/134 |
deploy-to-s3 |
/chapters/deploy-to-s3.html |
Now that our S3 Bucket is created we are ready to upload the assets of our app.
Create React App comes with a convenient way to package and prepare our app for deployment. From our working directory simply run the following command.
$ npm run build
This packages all of our assets and places them in the build/
directory.
Now to deploy simply run the following command; where YOUR_S3_DEPLOY_BUCKET_NAME
is the name of the S3 Bucket we created in the [Create an S3 bucket]({% link _archives/create-an-s3-bucket.md %}) chapter.
$ aws s3 sync build/ s3://YOUR_S3_DEPLOY_BUCKET_NAME
All this command does is that it syncs the build/
directory with our bucket on S3. Just as a sanity check, go into the S3 section in your AWS Console and check if your bucket has the files we just uploaded.
And our app should be live on S3! If you head over to the URL assigned to you (in my case it is http://notes-app-client.s3-website-us-east-1.amazonaws.com), you should see it live.
Next we'll configure CloudFront to serve our app out globally.