In this post, I will guide you through the steps to deploy a serverless Web Delivery Infrastructure using Amazon Web Services.
I use Amazon Web Services for my blog, ptylr.com. I deploy it using a serverless configuration consisting of:
The result is a simple to manage, highly-available, highly-scalable delivery topology that is also very cost-efficient.
Serverless Web Delivery Infrastructure Diagram
To deploy and maintain the infrastructure for ptylr.com, I use AWS CloudFormation.
Per Amazon themselves (https://aws.amazon.com/cloudformation/),
AWS CloudFormation allows you to use programming languages or a simple text file to model and provision, in an automated and secure manner, all the resources needed for your applications across all regions and accounts.
Yes, of course. You could configure each of the Amazon Services separately via the AWS CLI or Console. However, CloudFront is designed to take all the management effort away from you. It will automatically stand-up all of the infrastructure that you need, update it whenever you change the configuration and ultimately decommission it when no longer required. What’s more, there’s no additional charge for using CloudFormation - you pay only for the resources that it provisions.
CloudFormation > Create Stack
2) Under “Prerequisite - Prepare template”, select Template is ready and choose Amazon S3 URL in “Template Source”. Enter the location of the CloudFormation Template that you want to use. You are welcome to use mine, which will create the Serverless Web Delivery Infrastructure in the diagram above - (https://cloudformation-ptylr-com.s3.amazonaws.com/AWS-Serverless.yaml, then click Next.
CloudFormation > Select Template
3) Complete the following details and then click Next:
CloudFormation > Select Stack Details
4) The next screen (“Configure stack options”) allows you to configure properties on the Stack that you might want. I do not change the defaults and simply click Next.
CloudFormation > Configure Stack Options
5) Now review the deployment configuration that CloudFormation will build. You will need to check the box to confirm that “I acknowledge that AWS CloudFormation might create IAM resources.”. Once done, click Create Stack.
CloudFormation > Confirm
6) Sit back and relax while CloudFormation builds your Stack, provisioning Amazon S3, CloudFront, IAM Roles, Bucket Policies, Lambda Functions and CloudFront Behaviors.
CloudFormation > Building
Once your Stack has been provisioned, which will normally take around 15 minutes or so, you will be able to assign DNS Records to your CloudFront Distribution, upload some content into the S3 Bucket and start serving your content.
To assist, we have automatically deployed a pair of AWS Lambda@Edge Functions, designed to perform a number of roles normally associated with traditional web servers. A previous post discussed what these are used for - see https://ptylr.com/edgeservices-a-pair-of-lambda-at-edge-functions-for-executing-common-operations-on-request/.
Designed to replace functionality traditionally managed within web.config, web.xml or .htaccess files with a single JSON file, located within the root of an Amazon S3 Bucket (the origin). EdgeServices consists of a pair of AWS Lambda Functions, written in Node.js, which can be deployed to Lambda@Edge to support edge-node execution, ensuring high performance globally. The Lambda@Edge Functions are designed to execute upon both “Origin Request” and “Origin Response” Amazon CloudFront Behaviors, allowing the result to be cached for future requests, adding to the edge-based execution performance benefits.
Harness EdgeServices to:
EdgeServices Sequence Diagram
Configuration instructions are in the EdgeServices GitHub public repository, along with the source code, which is available under the MIT License. See https://github.com/ptylr/Lambda-at-Edge/tree/master/EdgeServices/.