A First Look at Amplify with Vite
Published:
AWS Amplify is a set of tools and services to help frontend web and mobile developers build scalable fullstack applications with AWS infrastructure.
Outline
All of this project’s code can be found in the First Look monorepo on my GitHub.
Introduction
AWS Amplify is a set of tools and services to help frontend web and mobile developers build scalable fullstack applications with AWS infrastructure that includes:
- Amplify Console for managing frontend web app, backend environments, CI/CD, and the Admin UI
- Amplify CLI for creating and deploying CloudFormation stacks
- Open source libraries for JavaScript, iOS, Android, and Flutter
- Admin UI for modeling data, adding authentication, authorization and managing users and groups
With these tools combined, Amplify has achieved a unique synecdoche¹ by creating their own opinionated version of AWS within AWS itself.
Setup
This tutorial will follow the Getting Started guide for React from the Amplify documentation, except we will be using Vite and the officially supported React template instead of create-react-app. This way the kids will know that I am, “with it.” The code for this article can be found on my GitHub.
Configure AWS CLI
Make sure you have the AWS CLI installed and an AWS account. For general use, aws configure
is recommended as the fastest way to set up your AWS CLI installation.
When you enter this command, the AWS CLI prompts you for four pieces of information:
- Access key ID
- Secret access key
- AWS Region
- Output format
Go to My Security Credentials to find your Access Key ID, Secret Access Key, and default region. You can leave the output format blank.
Install Amplify CLI
Initialize Project
You need a React app, which means first you have to create one. You could do the sensible thing and use a tool literally called create-react-app, or you could listen to a random person on the internet and use this thing you’ve never heard of and have no idea how to pronounce. If you’re not convinced you can refer to this blog post from the aforementioned random person on the internet.
Vite (French word for “fast”, pronounced /vit/
, rhymes with “street”) is a build tool that aims to provide a faster and leaner development experience for modern web projects. It consists of two parts:
- A dev server with Hot Module Replacement (HMR)
- A build command that bundles your code with Rollup, pre-configured to output highly optimized static assets for production
Output:
Start Development Server
You could click the counter. Or you could not click the counter and instead live the rest of life wondering whether it actually would have incremented or not.
Project Structure
Our package.json
includes scripts for starting the development server, building for production, and serving local previews of production builds.
App Component
Include links to your own social accounts.
Initialize Amplify Project
To initialize a new Amplify project, run amplify init
from the root directory of your frontend app.
Deploy to CloudFront and S3
Output:
You will then be taken to a very memorably named endpoint (ajcwebdevamplify-20210509181751-hostingbucket-dev.s3-website-us-west-1.amazonaws.com
in my case) for your S3 bucket.
[1] - wherein a part of something represents the whole, or vice versa.