Deploy frontend website to S3 with Serverless
Surprisingly, it can be difficult to easily deploy a website to S3 without using the amazon cli, sdk, or amplify.
Thankfully there is a plugin for serverless that now allows this to be easily accomplished.
Quick Start
Install serverless globally if you have not done so already:
1 | sudo npm install serverless -g |
After this you will want to setup serverless in the project that you are going to deploy your frontend files. You can do this simply by running:
1 | serverless |
Serverless will then ask you a few questions about your environment and generate the serverless.yml
file.
Take this file (you can discard the rest) and place the files you want to deploy to S3 in a folder structure of client/dist
with the serverless.yml
file alongside.
Modify the serverless.yml
file like so in your project:
1 | plugins: |
As you can see, you need to make sure the plugin called serverless-finch
is listed in your serverless file. Serverless generates comments and other services but for now, simply comment out everything else except what is shown above.
Additionally, you will want to install the serverless-finch
npm package:
1 | npm install --save serverless-finch |
Modify the S3 bucket name to the name of your website and then run:
1 | serverless client deploy |
Wam! You should now see something like this once your website has been deployed:
1 | Serverless: This deployment will: |
And then check out your deployed website at http://mywebsite.com.s3-website-us-east-1.amazonaws.com/