Deploy a Flutter Web Application Using AWS Amplify

Muhammed Salih Guler
5 min readJul 30, 2024

--

Deploy a Flutter Web Application Using AWS Amplify banner

Flutter is a UI toolkit used to create cross-platform applications for mobile, desktop, and web from a single codebase. Since developers can deploy their Flutter applications on the web without extra effort, they are seeking deployment options. With the release of AWS Amplify Gen 2, many new features have been announced for AWS Amplify. One notable feature is the simplified integration with Git workflows for both backend and hosting solutions, enabled by Amplify Console’s new user interface.

In this blog post, you will learn how to host a Flutter web application using Amplify Hosting, with the project code stored on GitHub. This tutorial is compatible with any supported Git provider, so you can also use BitBucket, GitLab, and CodeCommit.

Requirements:

  • An AWS account
  • Flutter SDK installed on your device
  • An account on any supported Git provider, this blog post will be using GitHub

Creating a Flutter Project

Start by creating a Flutter project with web support by running the following command:

flutter create amplify_gen2_website --platform web

This will create a Flutter project with only web support enabled. The next step is to move our code to GitHub. You can do this using any Git tool you prefer. In this example, you will learn how to share it using VSCode.

First, open the project in VSCode and open the Command Palette by pressing Shift + Command + P (Mac) or Ctrl + Shift + P (Windows/Linux). Next, select the “Share on GitHub” option:

VSCode UI with Command Palette open and “Publish to GitHub” option is highlighted

Next, choose either a private or public repository based on your preference. Give your repository a name, and then the app will be shared on GitHub.

VSCode UI to select GitHub repository type

Once the upload is done, the project can be seen on GitHub.

GitHub project structure for the created Flutter project

Afterwards, go to the AWS Amplify in the AWS console and “Create new app” button.

AWS Amplify Console with a “Create New App” button and “See how it works” button. At the bottom of the page the list of supported platforms indicated

Select GitHub (or your Git provider) as your Git provider.

AWS Amplify project creation screen with GitHub, BitBucket, CodeCommit and GitLab as Git provider options and an option to deploy without Git

Once you select the Git provider and continue, you will be prompted to grant AWS Amplify permission to access your repositories.

GitHub sign in for AWS Amplify to have access

After granting access to AWS Amplify, you can now select the project and branch you want to deploy.

List of projects from the Git Provider for users to select

Once you select your project and branch, the App Settings will be displayed. Update the “Frontend build command” to flutter build web and set the “Build output directory” to /build/web. After making these changes, click "Next" and proceed with the review step. Your initial deployment will then begin.

App settings with app name, frontend build command and build directory

You will see that your initial build will fail because the Flutter toolchain is not installed on your build system.

main branch deployment fail status is shown on the project page

To fix this, you will need to update your build configuration file. Go to Hosting/Build settings in the left hand side navigation bar and locate the amplify.yml file.

amplify.yml file with the set of steps to install flutter and build it

Update the amplify.yml file with the following. This approach uses WASM (WebAssembly) for Flutter Web to host the app and bring out better and faster performance:

version: 1.0
frontend:
phases:
preBuild:
commands:
- echo "Installing Flutter SDK"
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
- export PATH="$PATH:$(pwd)/flutter/bin"
- flutter config --no-analytics
- flutter doctor
- echo "Installing dependencies"
- flutter pub get
build:
commands:
- echo "Building Flutter web application with WASM support"
- flutter build web --wasm
artifacts:
baseDirectory: build/web
files:
- '**/*'
cache:
paths:
- flutter/.pub-cache

Now, go back to the deployments under your branch and click on the “Redeploy this version” button:

Deployment page with deployment history with latest deploy’s build and deployment time

After the deployment, a domain will be automatically assigned to your build. Click on the assigned domain to check your deployment.

Basic Flutter Web application with a counter on the center

Now let’s see how the update through CI/CD mechanism works. Update the code to change the title of the page, the color scheme, and the title of the app, as shown below:

VSCode page with code changes described above

You can see that with every push to Git, the deployment will be triggered automatically:

New deployment with the auto update

With these changes, if you run the application again, you will see the updated UI.

Same counter app with updated title and color scheme

Conclusion

In this blog post, you have learned about how to host a Flutter Web project with Amplify Hosting. You can check out the Amplify Gen 2 docs to learn more about AWS Amplify Gen 2 and the Amplify Hosting page to learn about Amplify Hosting.

--

--