Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Serverless Applications with Go

You're reading from   Hands-On Serverless Applications with Go Build real-world, production-ready applications with AWS Lambda

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789134612
Length 416 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Mohamed Labouardy Mohamed Labouardy
Author Profile Icon Mohamed Labouardy
Mohamed Labouardy
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Go Serverless 2. Getting Started with AWS Lambda FREE CHAPTER 3. Developing a Serverless Function with Lambda 4. Setting up API Endpoints with API Gateway 5. Managing Data Persistence with DynamoDB 6. Deploying Your Serverless Application 7. Implementing a CI/CD Pipeline 8. Scaling Up Your Application 9. Building the Frontend with S3 10. Testing Your Serverless Application 11. Monitoring and Troubleshooting 12. Securing Your Serverless Application 13. Designing Cost-Effective Applications 14. Infrastructure as Code 15. Assessments 16. Other Books You May Enjoy

AWS Lambda

AWS Lambda is the center of the AWS serverless platform:

AWS Lambda was launched at re:Invent 2014. It was the first implementation of serverless computing where users could upload their code to Lambda. It performs operational and administrative activities on their behalf, including provisioning capacity, monitoring fleet health, applying security patches, deploying their code, and publishing realtime logs and metrics to Amazon CloudWatch.

Lambda follows the event-driven architecture. Your code is triggered in response to events and runs in parallel. Every trigger is processed individually. Moreover, you are charged only per execution, while with EC2 you are billed by the hour. Therefore, you benefit from autoscaling and fault-tolerance for your application with low cost and zero upfront infrastructure investment.

Source events

AWS Lambda runs your code in response to events. Your function will be invoked when these event sources detect events:

Amazon is now supporting SQS as a source event for Lambda

Use cases

AWS Lambda can be used for endless application scenarios:

  • Web applications: Instead of a maintaining a dedicated instance with a web server to host your static website, you can combine S3 and Lambda to benefit from scalability at a cheaper cost. An example of a serverless website is described in the following diagram:

An alias record in Route 53 points to a CloudFront distribution. The CloudFront distribution is built on top of an S3 Bucket where a static website is hosted. CloudFront reduces the response time to static assets (JavaScripts, CSS, fonts, and images), improves webpage load times, and mitigates distributed denial of service (DDoS) attacks. HTTP requests coming from the website then go through API Gateway HTTP endpoints that trigger the right Lambda Function to handle the application logic and persist data to a fully managed database service, such as DynamoDB.

  • Mobile and IoT: A schematic for building a sensor application, which measures the temperature from a realtime sensor-connected device and sends an SMS alert if the temperature is out of range, can be given as follows:

The Connected Device will ingest data to AWS IoT. AWS IoT rules will invoke a Lambda Function in order to analyze the data and publish a message to an SNS Topic in case of emergency. Once the message is published, Amazon SNS will attempt to deliver that message to every endpoint that is subscribed to the topic. In this case it will be an SMS.

  • Data ingestion: Monitoring your logs and keeping an audit trail is mandatory, and you should be aware of any security breaches in your cloud infrastructure. The following diagram illustrates a realtime log-processing pipeline with Lambda:

The VPC Flow Logs feature captures information about the IP traffic going to and from network interfaces in your VPC and ships the logs to Amazon CloudWatch Logs. AWS CloudTrail maintains records of all AWS API calls on your account. All logs are aggregated and streamed to AWS Kinesis Data Streams.

Kinesis triggers Lambda Functions, which analyze logs for events or patterns and send a notification to Slack or PagerDuty in the event of abnormal activity. Finally, Lambda posts the dataset to Amazon Elasticsearch with a pre-installed Kibana to visualize and analyze network traffic and logs with dynamic and interactive dashboards. This is done for long-term retention and to archive the logs, especially for organizations with compliance programs. Kinesis will store logs in S3 bucket for backup. The bucket can be configured with a life cycle policy to archive unused logs to Glacier.

  • Scheduling tasks: Scheduled tasks and events are a perfect fit for Lambda. Instead of keeping an instance up and running 24/7, you can use Lambda to create backups, generate reports, and execute cron-jobs. The following schematic diagram describes how to use AWS Lambda to perform a post-processing job:

When a video arrives at an S3 bucket, an event will trigger a Lambda Function, which will pass the video filename and path to an Elastic Transcoder pipeline to perform video transcoding, generate multiple video formats (.avi, .h264, .webm, .mp3, and so on), and store the results in an S3 bucket.

  • Chatbots and voice assistants: You can use a Natural Language Understanding (NLU) or Automatic Speech Recognition (ASR) service, such as Amazon Lex, to build application bots that can trigger Lambda Functions for intent fulfillment in response to voice commands or text. The following diagram describes a use case for building a personal assistant with Lambda:

A user can ask Amazon Echo about its to-do list. Echo will intercept the user's voice command and pass it to a custom Alexa Skill, which will carry out speech recognition and transform the user's voice commands into intents, which will trigger a Lambda Function that in turn will query Trello API to fetch a list of tasks for today.

Due to Lambda's limitation in terms of memory, CPU, and timeout execution, it's not suited for long-running workflows and other massive workloads.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime