Angular on AWS with SST
Create and deploy an Angular app to AWS with SST.
We are going to create an Angular 18 SPA, add an S3 Bucket for file uploads, and deploy it to AWS using SST.
Before you get started, make sure to configure your AWS credentials.
1. Create a project
Let’s start by creating our project.
We are picking CSS for styles, and not using SSR.
Init SST
Now let’s initialize SST in our app.
This’ll create a sst.config.ts
file in your project root.
2. Add an S3 Bucket
Let’s allow public access
to our S3 Bucket for file uploads. Update your sst.config.ts
.
Add this above the StaticSite
component.
We are going to upload a file to this bucket using a pre-signed URL. This’ll let us upload it directly to our bucket.
3. Add an API
Let’s create a simple API to generate that URL. Add this below the Bucket
component.
We are linking our bucket to this function.
Pass the API URL
Now, pass the API URL to our Angular app. Add this below the build
prop in our StaticSite
component.
To load this in our Angular app, we’ll use the @ngx-env/builder
package.
Start dev mode
Run the following to start dev mode. This’ll start SST and your Angular app.
Once complete, click on MyWeb in the sidebar and go to your Angular app in your browser. Typically on http://localhost:4200
.
3. Create an upload form
Let’s create a component to do the file upload. Add the following to src/app/file-upload.component.ts
.
This is getting the pre-signed API URL from the environment. Making a request to it to get the pre-signed URL and then uploading our file to it.
Let’s add some styles
below the template
prop.
To make HTTP fetch requests we need to add the provider to our Angular app config. Add the following to the providers
list in src/app/app.config.ts
.
And import it at the top.
Let’s add this to our app. Replace the src/app/app.component.ts
file with.
4. Generate a pre-signed URL
Let’s implement the API that generates the pre-signed URL. Create a functions/presigned.ts
file with the following.
And install the npm packages.
Head over to the local Angular app in your browser, http://localhost:4200
and try uploading an image. You should see it upload and then download the image.
5. Deploy your app
Now let’s deploy your app to AWS.
You can use any stage name here but it’s good to create a new stage for production.
Connect the console
As a next step, you can setup the SST Console to git push to deploy your app and monitor it for any issues.
You can create a free account and connect it to your AWS account.