Why should you consider creating a serverless application ?
Building a serverless application doesn’t only allow you to configure and run applications without even thinking about servers, it also lets you focus on your application code instead of worrying about provisioning, configuring, and managing an infrastructure, which grants you a lot of benefits.
Fully-managed servers don’t require any intervention for installation, configuration or maintenance. The whole infrastructure is auto-managed and provides a running application with total high availability | The serverless approach is ideal and flexible for scaling applications. AWS handles all your functions and runs them separately. This gives you a chance to scale them automatically and endlessly. With serverless, you don’t have to purchase an approximated amount of resources, you can be as flexible as manageable. | Serverless approach saves time and resources. It’s a pay as you go computing which means you are charged the memory and time allocated to your code. Cost benefits include lack of operating system costs including installation, dependencies, support, and maintenance. This saves cost in a huge way. The traffic you have determines what you pay. |
How to build a serverless application ?
You can build a serverless web application by using several AWS services together. Each service is fully managed and does not require you to provision or manage servers. You only need to configure them together and they will assist you in building a fully scalable,highly available serverless web application.
You can accomplish that by following the architecture that is presented to you down below :
The implementation of a serverless infrastructure in AWS is divided to 4 modules using interconnected services :
1. Select a web hosting service : AWS offers Amazon S3 as a managed service that provides simple, durable, scalable object storage that you can use to host your web application.
In order to create an S3 bucket, AWS asks you to enter :
- Bucket name : The bucket name has to be unique and never used before on any Amazon S3 buckets, so always try to personalize the name of your bucket.
- Region : Select the region in which you want to create the bucket.
2.Select a serverless backend service : AWS puts at your disposal AWS Lambda as a managed service for serverless compute that allows you to run code without provisioning or managing servers.
Lambda functions could be written in different languages : Java, Go, PowerShell, Node.js, C#, Python, and Ruby.
When it comes to Lambda, Amazon gives you the ability to choose from several options to create a Lambda function.
-> Author from scratch : is a “Hello World” example that includes just enough code of your chosen language to get you started. You can add triggers and configure additional settings later.
In this option, Lambda allows you to make a “basic function settings“ where you put in :
- The name of the function
- The language you want to use
- An IAM role with the right permissions to use Lambda functions
If you want you Lambda function to reach out to an external VPC, you have to configure Lambda “advanced function settings” where you have to put in :
- an ARN ( optional)
- Network settings : a VPC , a Subnet and a Security Group that will automatically generate an Elastic Network Interface for your function.
-> Use a blueprint : blueprints are language-specific samples that include function code and settings for a runtime and trigger combination. Blueprints are available for Node.js and Python runtimes.
-> Container image : allows you to select a container image to deploy as your Lambda function.
-> Browse serverless app repository : is a list of sample applications from the AWS Serverless Application Repository are fully functional Lambda applications. They use the AWS Serverless Application Model (AWS SAM) with AWS CloudFormation and include an execution role, function trigger, and other resources.
3.Select a RESTful Apis : Amazon Api Gateway is a managed Amazon service which you can use to create, publish, and maintain secure APIs
4.Select a Database : Amazon DynamoDB is a fast and flexible NoSQL managed cloud database with support for various document and key-value storage models.
Your infrastructure at this level could be up and running on the cloud but you still need to ensure the security of your data and services.
To do so you need to apply the following diagram :
5.Select a privileged access management service : Amazon Identity and Access Management (IAM) enables you to manage access to AWS services and resources securely. Using IAM, you can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources.
6.Select a user management service : Amazon Cognito is a managed service that allows you to add user sign-up, and data synchronization to your application,which means it provides user management and authentication functions to secure your backend API.