2 minutes
Deploy Vue.js Website to AWS S3
How to build a Vue.js static single-page app and deploy it to AWS S3 with GitHub Actions and Route 53.
Static Vue.js single-page applications (SPAs) don’t need a Node server in production—once compiled into static HTML, JS, and CSS assets, they can be served directly from an AWS S3 bucket behind CloudFront or Route 53.
1. Configure the S3 Bucket for Static Hosting
- In the AWS S3 Console, click Create bucket.
- Name the bucket after your domain (e.g.,
your-website-url.com), pick your AWS region, and create the bucket. - Open the Properties tab, scroll to Static website hosting, and enable it:
- Index document:
index.html - Error document:
index.html(important for Vue Router in history mode so deep links resolve to your SPA)
- Index document:
- In the Permissions tab, allow public read access to the bucket objects with a Bucket Policy (or via a CloudFront Origin Access Identity if serving strictly through CloudFront):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET_NAME>/*"
}
]
}
Replace <BUCKET_NAME> with your bucket name.
2. Build the Vue.js App for Production
Create or build your Vue project:
npm create vue@latest my-project
cd my-project
npm install
npm run build
npm run build outputs the minified production assets into the dist/ directory.
3. Automate Deployment with GitHub Actions
While you can upload the dist/ contents manually from the S3 console or with aws s3 sync dist/ s3://your-website-url.com --delete, automating it on every push to main is much cleaner:
# .github/workflows/build.yaml
name: Vue Build and Deploy to S3
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- uses: jakejarvis/s3-sync-action@master
if: github.event_name == 'push'
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: your-website-url.com
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: eu-central-1
SOURCE_DIR: 'dist'
4. Point a Custom Domain with Route 53
- In Route 53, create (or open) the Hosted Zone for your domain.
- Create an A record with Alias enabled pointing to the S3 website endpoint (or your CloudFront distribution if you want HTTPS).
- Make sure your domain registrar’s nameservers match the NS records of your Route 53 Hosted Zone.
(For full HTTPS support with S3 + CloudFront + Terraform, see my earlier post on hosting a static website in AWS.)