March 2, 2019

Serverless Series - Serverless Services used in Demo

 Serverless Series HomeLet's have a closer look the 4 Serverless Services that will be used in today's Demo. 




Amazon S3

S3 is the massive storage and one of the back bones of AWS. Infact this was first service launched by AWS
How much data can I store?
The total volume of data and number of objects you can store are unlimited. Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 terabytes. The largest object that can be uploaded in a single PUT is 5 gigabytes. For objects larger than 100 megabytes, customers should consider using the Multipart Upload capability.

What storage classes does Amazon S3 offer?
Amazon S3 offers a range of storage classes designed for different use cases. There are three highly durable storage classes including 
  • S3 Standard for general-purpose storage of frequently accessed data
  • S3 Intelligent-Tiering storage class is designed to optimize costs by automatically moving data to the most cost-effective access tier, without performance impact or operational overhead. 
  • S3 Standard - Infrequent Access for long-lived, but less frequently accessed data, 
  • S3 One Zone-IA is for data that is accessed less frequently, but requires rapid access when needed. Unlike other S3 Storage Classes which store data in a minimum of three Availability Zones (AZs), S3 One Zone-IA stores data in a single AZ and costs 20% less than S3 Standard-IA. 
  • S3 Glacier  is a secure, durable, and low-cost storage class for data archiving.
  • S3 Glacier Deep Archive is Amazon S3’s lowest-cost storage class and supports long-term retention and digital preservation for data that won’t be regularly accessed. It is designed for customers — particularly those in highly-regulated industries, such as the Financial Services, Healthcare, and Public Sectors — that retain data sets for 7-10 years or longer to meet regulatory compliance requirements. 

S3 Storage Classes can be configured at the object level and a single bucket can contain objects stored in S3 Standard, S3 Intelligent-Tiering, S3 Standard-IA, and S3 One Zone-IA. For further reading on S3 Storage Classes, refer https://aws.amazon.com/s3/storage-classes/.


 Amazon CloudWatch

CloudWatch sits under Management Tools in AWS Console and can monitor any AWS Services – ALB, EBS, EC2, ELB, S3 etc
  • Metrics - For example, basic host level metrics like CPU Utilization, DiskOps etc are monitored where OS level metrics like memory would need you to write custom metrics. Documentations are available for the same.
  • Dashboards – Creates awesome dashboards to see what is happening with your AWS Environment. 
  • Alarms – Allows you to set Alarms that notify you when particular thresholds are hit. 
  • Events – CloudWatch events helps you to respond to state changes in your AWS resources  
  • Logs – CloudWatch Logs helps you to aggregate, monitor, and store logs. 

Amazon API Gateway
Amazon API Gateway is an AWS service that enables you to create, publish, maintain, monitor, and secure your own APIs at any scale. You can create robust, secure, and scalable APIs that access AWS or other web services, as well as data stored in the AWS Cloud
  • Support for stateful (WebSocket) and stateless (REST) APIs
  • Integration with AWS services such as AWS Lambda, Amazon Kinesis, and Amazon DynamoDB
  • There are two kinds of developers who use API Gateway: API developers and app developers.
    • An API developer creates and deploys an API to enable the required functionality in API Gateway. The API developer must be an IAM user in the AWS account that owns the API.
    • As an API developer, you can create and manage an API by using the API Gateway console, CLI, SDK or Cloud Formation Template
    • An app developer builds a functioning application to call AWS services by invoking a WebSocket or REST API created by an API developer in API Gateway.
    • The app developer is the customer of the API developer. The app developer does not need to have an AWS account, provided API is designed that way.
Together with AWS Lambda, API Gateway forms the app-facing part of the AWS serverless infrastructure

AWS Lambda

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume - there is no charge when your code is not running. With AWS Lambda, you can run code for virtually any type of application or backend service - all with zero administration. AWS Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. 
  • All you need to do is supply your code in one of the languages that AWS Lambda supports (currently Node.js, Java, C# and Python). 
  • You can use AWS Lambda  
    • (1) to run your code in response to events (Event Driven), such as changes to data in an Amazon S3 bucket or an Amazon DynamoDB table;  
    • (2) to run your code in response to HTTP requests using Amazon API Gateway; or invoke your code using API calls made using AWS SDKs.  
  • Lambda functions are independent but one lambda function can trigger other lambda functions 
  • Lambda scales automatically and also can perform actions globally like copying files from S3 in one region to other region.

Pricing at high-level:

  • S3 - new AWS customers receive 5 GB of Amazon S3 Standard storage, 20,000 Get Requests, 2,000 Put Requests, 15GB of data transfer in, and 15GB of data transfer out each month for one year.
    • ~ 0.23/per GB update 50GB
  • API Gateway 
    • Rest API 
      • Pay only for the API calls you receive and the amount of data transferred out
      • For better performance and faster API execution, you can optionally provision a dedicated cache for each stage of your APIs. After you specify the size of the cache you require, you will be charged the following hourly rates for each stage’s cache, without any long-term commitments.
      • Free Tier - 1M API CALLS RECEIVED | 1M MESSAGES | 750,000 CONNECTION MINUTES
    • WebSocket APIs
      • Pay only for messages sent and received and the total number of connection minutes. You may send and receive messages up to 128 kilobytes (KB) in size. Messages are metered in 32 KB increments. So, a 33 KB message is metered as two messages.
      • For WebSocket APIs, the API Gateway free tier includes one million messages (sent or received) and 750,000 connection minutes for up to 12 months.
  • AWS Lambda
    • Lambda counts a request each time it starts executing in response to an event notification or invoke call, including test invokes from the console. You are charged for the total number of requests across all your functions.  
  • Amazon CloudWatch
    • Basic Monitoring Metrics (at 5-minute frequency) where detailed monitoring Metrics (at 1-minute frequency) is charged
    • Example: EC2 Detailed Monitoring is priced at $2.10 per instance per month and goes down to $0.14 per instance at the lowest priced tier.) 

For the Sample that we are going to try today, trust me that it won’t incur any charge if you clean-up diligently :). 


Serverless Series - Introduction to Serverless

 Serverless Series Home Evolution of Cloud

The age old practise of self-managed servers had big time trouble and the data centre, where someone will manage your infrastructure, came as saviour to get away from managing hardware all by yourself. Since then evolution of each era with a technological transformation have been phenomenal from IaaS, PaaS, CaaS & FaaS



Launch of EC2 instance in 2006 was a stepping stone for Infrastructure as a service providing compute platform at scale.  And the journey continued swiftly with Platform as a service, Container as a Service and finally Amazon Lambda was launched as Function as a Service in 2015.

IaaS (Infrastructure as a Service)
At a basic level, IaaS public cloud providers offer storage and compute services on a pay-per-use basis. But the full array of services offered by all major public cloud providers is staggering: highly scalable databases, virtual private networks, big data analytics, developer tools, machine learning, application monitoring, and so on. Amazon Web Services was the first IaaS provider and remains the leader, followed by Microsoft Azure, Google Cloud Platform, and IBM Cloud.
PaaS (Platform as a Service)
PaaS provides sets of services and workflows that specifically target developers, who can use shared tools, processes, and APIs to accelerate the development, test, and deployment of applications. Salesforce’s Heroku and Force.com are popular public cloud PaaS offerings; Pivotal’s Cloud Foundry and Red Hat’s OpenShift can be deployed on premises or accessed through the major public clouds. For enterprises, PaaS can ensure that developers have ready access to resources, follow certain processes, and use only a specific array of services, while operators maintain the underlying infrastructure.
Note that a variety of PaaS tailored for developers of mobile applications generally goes by the name of MBaaS (mobile back end as a service), or sometimes just BaaS (back end as a service).

CaaS(Container as a Service)Containers as a service (CaaS) is a cloud service that allows software developers to upload, organize, run, scale, manage and stop containers by using a provider's API calls or a web portal interface.
FaaS (functions as a service)
FaaS, the cloud instantiation of serverless computing, adds another layer of abstraction to PaaS, so that developers are completely insulated from everything in the stack below their code. Instead of futzing with virtual servers, containers, and application runtimes, they upload narrowly functional blocks of code, and set them to be triggered by a certain event (e.g. a form submission or uploaded file). All the major clouds offer FaaS on top of IaaS: AWS Lambda, Azure Functions, Google Cloud Functions, and IBM OpenWhisk. A special benefit of FaaS applications is that they consume no IaaS resources until an event occurs, reducing pay-per-use fees.

Mysteries around Servers

Endless open questions while dealing with servers keep flashing around all the time and Serverless had answers to all those mysteries.



What is Serverless?

Serverless does not mean that no servers! We all know that any action or task to be performed need a server. So what does Serverless mean?

Serverless is the native architecture of the cloud that enables you to shift more of your operational responsibilities to AWS, increasing your agility and innovation.
Serverless allows you to build and run applications and services without thinking about servers, meaning servers are abstracted from the end user who avails the serverless functionality.
It eliminates infrastructure management tasks such as server or cluster provisioning, patching, operating system maintenance, and capacity provisioning.

Advantages of going Serverless



Serverless Series - The AWS Serverless Platform

 Serverless Series HomeAWS provides a set of fully managed services that you can use to build and run serverless applications. Serverless applications don’t require provisioning, maintaining, and administering servers for backend components such as compute, databases, storage, stream processing, message queueing, and more. You also no longer need to worry about ensuring application fault tolerance and availability. Instead, AWS handles all of these capabilities for you. This allows you to focus on product innovation while enjoying faster time-to-market.

Compute

  • AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no charge when your code is not running. 
  • Lambda@Edge allows you to run Lambda functions at AWS Edge locations in response to Amazon CloudFront events.
  • AWS Fargate is a purpose-built serverless compute engine for containers. Fargate scales and manages the infrastructure required to run your containers.

Storage

  • Amazon Simple Storage Service (Amazon S3) provides developers and IT teams with secure, durable, highly-scalable object storage. Amazon S3 is easy to use, with a simple web service interface to store and retrieve any amount of data from anywhere on the web.
  • Amazon Elastic File System(Amazon EFS) provides simple, scalable, elastic file storage. It is built to elastically scale on demand, growing and shrinking automatically as you add and remove files. 

Data Stores

  • Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale.
  • Amazon Aurora Serverless is an on-demand, auto-scaling configuration for Amazon Aurora (MySQL-compatible edition), where the database will automatically start up, shut down, and scale capacity up or down based on your application's needs.

API Proxy

  • Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. Amazon API Gateway allows you to process hundreds of thousands of concurrent API calls and handles traffic management, authorization and access control, monitoring, and API version management.



Interprocess Messaging

  • Amazon SNS is a fully managed pub/sub messaging service that makes it easy to decouple and scale microservices, distributed systems, and serverless applications.
  • Amazon SQS is a fully managed message queuing service that makes it easy to decouple and scale microservices, distributed systems, and serverless applications.  

Orchestration

  • AWS Step Functions makes it easy to coordinate the components of distributed applications and microservices using visual workflows. Building applications from individual components that each perform a discrete function lets you scale and change applications quickly. Step Functions is a reliable way to coordinate components and step through the functions of your application.

Analytics

  • Amazon Kinesis is a platform for streaming data on AWS, offering powerful services to make it easy to load and analyze streaming data, and also providing the ability for you to build custom streaming data applications for specialized needs.
  • Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. Athena is serverless, so there is no infrastructure to manage, and you pay only for the queries that you run.

Developer Tooling

  • AWS provides tools and services that aid developers in the serverless application development process. AWS and its partner ecosystem offer tools for continuous integration and delivery, testing, deployments, monitoring and diagnostics, SDKs, frameworks, and integrated development environment (IDE) plugins.


Refer here for more details from AWS on the serverless platform.

Serverless Series - Serverless WebApp - Use Case 1

 Serverless Series HomeThis blog post will be taking you through the step by step instructions to build Serverless WebApp - Use Case 1 which will cover network diagram, output webpage, steps to create & configure lambda function, configure API Gateway & create S3 static website for hosting webpages.

Network Diagram



Output WebPage

Here is the expected output page for you to work with an end goal in mind!


Create & Configure Lambda Function

Create Lambda function




 Create Lambda Execution Role

Configure Lambda Function



Edit Lambda function

Configure Lambda function



Configure Lambda function 


Add API Gateway Triggers to Lambda function


Configure Trigger


If the deployment Stage do not exist, create one as in next image & then adding API Gateway Trigger


 Configure Trigger



Configure API Gateway method


API Gateway - Remove ANY method


API Gateway - Remove ANY method


API Gateway - Add GET method




Copy the API Gateway URL & browse it to view the output from the Lambda function. If you get the error "message": "Missing Authentication Token", error Deploying the API again will help.

Create Static Website on S3

  • Create S3 Bucket – public objects; static website
  • Edit index.html to place API Gateway link
  • Upload error.html & index.html; make public
  • Browse using S3 Static Website end point

Serverless Series - MindMap for Use Case 1 & Use Case 2


 Serverless Series Home
Here is the mindmap for Serverless WebApp - Use Case 1 & Use Case 2