Building SPAs with Serverless Framework

As well as building and maintaining the resources and configurations with CloudFormation, the CLI, or in the console directly, we can also manage the components in the Serverless Framework. To make it even easier, we can leverage the serverless SPA plugin:

  1. To install it, this time, we're going to use the serverless install command to create the new service. That's because this command has an option to input a URL, and we're going to input a URL that contains a boilerplate structure for an SPA project. Have a look at the following command:
sls install 
--url https://github.com/serverless/examples/tree/master/aws-node-single-page-app-via-cloudfront
--name hello-website

What this command does is seed our service with the configuration we need to get started.

  1. After running the command, have a look at the serverless.yml file to view all of the resources that will be created.
  2. The minimum configuration you need to do is update the S3 bucket key with your bucket name.
  3. When you deploy the service using the sls deploy command, it might take 15 minutes or so for the CloudFront distribution to replicate around the edge locations.

The plugin also comes with a useful command to upload your files to the S3 bucket. You can use this command to sync the directory called app in your project space to S3. 

Once you have deployed your SPA service, try the following command to push your content to S3. This simple process can be used as a content deployment mechanism, and there are no other services that need to be configured or restarted for the deployment to take effect:

sls syncToS3

You can use this command any time you need to deploy new or updated content into your bucket.

It's as easy as that! In this section, we learned the basics of creating an SPA project with Serverless Framework. There aren't many steps to it, so it should be clear how easy it is to get started building your own SPA on AWS.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.167.183