You can build search-engine optimized (SEO) friendly single page applications (SPA’s) with Angular Universal, a technology that runs your Angular application on the server. And you can reduce the cost of running those applications with AWS Lambda, an event-driven, serverless computing platform provided as a part of Amazon Web Services (AWS). This post will show you how to build and deploy Angular Universal projects on AWS Lambda using Serverless Framework, an open-source command line interface for building and deploying serverless applications.

In this post we will:

Create an Angular application that contains two routes and makes calls to an external API

Add server-side rendering for SEO purposes

Set up a Serverless Framework framework configuration

Deploy the app on AWS Lambda

To accomplish the tasks in this post you will need to create an AWS account and install the following:

To configure the AWS CLI you’ll need the following from your AWS account:

Access Key ID

Secret Key

Default region

Your root user will have all the rights necessary to deploy and run the Angular app as a Lambda function. You can get an Access Key ID and a Secret Key for your root user by generating a new pair in the Identity and Access Management (IAM) console.

If you do not want to use your root user ID for this project you can Set Up an IAM Role and Policy for an API to Invoke Lambda Functions. This process has a number of steps and is not recommended if you are new to AWS.

Be sure you have completed all these tasks successfully before proceeding.

Set up the Angular project and run Hello World!

The first step we must take in every Angular project is initialization and installation of the package: