This is a template for deploying a Angular application onto a serverless website via the Website Component. The project was generated with Angular CLI version 11
The Serverless Website Component sets up everything you need within seconds. It uses AWS S3 for hosting, AWS Cloudfront for a blazing fast CDN, AWS Route 53 to configure your custom domain and an AWS ACM Certificate to secure your with with SSL.
Overall, this infrastructure stack is perhaps the cheapest possible way to deploy a front-end application, that is massively scalable, and performant.
Install the Serverless Framework:
$ npm i -g serverless
Add the access keys of an AWS IAM Role with AdministratorAccess
in a .env
file, using this format:
AWS_ACCESS_KEY_ID=1234
AWS_SECRET_ACCESS_KEY=1234
Install the project dependencies
npm install
Or, you can set these as environment variables manually before deploying.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.
Deploy via the serverless
command:
$ serverless
Use the --debug
flag if you'd like to learn what's happening behind the scenes:
$ serverless --debug
If you aren't using a custom domain, AWS Cloudfront and HTTPS://
will not be set up. Instead, you will receive an HTTP://
domain from AWS S3.
When you add a custom domain, AWS Cloudfront and HTTPS://
will be set up automatically with it.
Remember, once you deploy with a custom domain for the first time, it may take up to an hour for DNS servers to propagate that change.
Checkout the Serverless Components repo for more information.