无服务器应用程序简介

In this article, I am going to describe what are serverless applications and how are these developed. I will also introduce the concepts of serverless computing and how to deploy one using Azure Functions. This article is targeted towards most of the data professionals who want to gain some basic knowledge of serverless applications and the underlying architecture and cloud computing. In recent times, cloud computing has become one of the most important domains for many big organizations and it has thus become essential for all to have some basic information on the same.

在本文中,我将描述什么是无服务器应用程序以及如何开发它们。 我还将介绍无服务器计算的概念以及如何使用Azure Functions进行部署。 本文针对希望获得无服务器应用程序,底层架构和云计算的一些基础知识的大多数数据专业人员。 最近,云计算已成为许多大型组织最重要的领域之一,因此对于所有人而言,拥有一些基本信息就变得至关重要。

Although there are multiple serverless offerings from Azure, in this article, we will cover only Azure Functions and the topics related to it. We will go through the languages supported by it, the authoring choices, how to test the function, how to monitor the logging, and how to set the authorization level of these functions, etc.

尽管Azure提供了多种无服务器产品,但在本文中,我们将仅介绍Azure Functions及其相关主题。 我们将介绍它所支持的语言,创作选择,如何测试功能,如何监视日志记录以及如何设置这些功能的授权级别等。

什么是无服务器应用程序 (What are serverless applications)

In the cloud computing world, it is often the case that the cloud provider provides the infrastructure necessary to run the applications to the users. The cloud provider takes care of all the headaches of running the server, dynamically managing the resources of the machine, etc. It also provides auto scalability, which means the serverless applications can be scaled based on the execution load they are exposed to. All these are done so that the user can solely focus on writing the code and leave worrying about these tasks to the cloud provider.

在云计算世界中,云提供商通常提供向用户运行应用程序所需的基础架构。 云提供商解决了运行服务器,动态管理机器资源等所有麻烦问题。它还提供了自动可伸缩性,这意味着可以根据无服务器应用程序所承受的执行负载对其进行扩展。 完成所有这些操作后,用户就可以只专注于编写代码,而不必担心将这些任务留给云提供商。

Serverless applications, also known as Function-as-a-Service or FaaS, is an offering from most of the enterprise cloud providers in which they allow the users to only write code and the infrastructure behind the scenes is managed by them. Users can write multiple functions to implement business logic and then can all these functions can be easily integrated to talk to each other. Such a system that involves the use of the above model is known as serverless architecture.

无服务器应用程序,也称为功能即服务FaaS ,是大多数企业云提供商提供的产品,它们允许用户仅编写代码,而幕后的基础架构由他们管理。 用户可以编写多个功能来实现业务逻辑,然后可以轻松地将所有这些功能集成在一起以相互交流。 涉及使用上述模型的这种系统称为无服务器架构。

Let us now see some of the basic FaaS offerings from the enterprise cloud providers.

现在让我们来看一下企业云提供商提供的一些基本的FaaS产品。

  1. Azure Functions, from Microsoft Azure Functions
  2. AWS Lambda, from Amazon Web Services (AWS) AWS Lambda
  3. Google Cloud Functions, from Google Google的Google Cloud Functions
  4. OpenWhisk, an open-source cloud platform from Apache/IBM OpenWhisk ,来自Apache / IBM的开源云平台
  5. Fn Project, from Oracle Fn项目

Although serverless architecture is the new boom, we need to be aware of the following two main concepts.

尽管无服务器架构是新的热潮,但是我们需要注意以下两个主要概念。

  • These functions are stateless – which means the state of these applications is created when the execution starts and destroyed when the function has been executed successfully. There is no state information being store automatically about these functions. In case, the users need to store the state information, a separate storage system like a database can be used 这些函数是无状态的 –这意味着这些应用程序的状态在执行开始时创建,并在该函数成功执行后销毁。 没有自动存储有关这些功能的状态信息。 如果用户需要存储状态信息,则可以使用单独的存储系统(如数据库)
  • These functions are event-driven – this means that you need an event that occurs before executing these functions. An event can be anything like a REST API request, a message added to a queue, etc. The response from the event, also known as a trigger, can be used to fire the execution of a serverless application
  • 这些功能是事件驱动的 –这意味着您需要在执行这些功能之前发生一个事件。 事件可以是诸如REST API请求,添加到队列中的消息之类的任何事件。事件的响应(也称为触发器 )可用于触发无服务器应用程序的执行

Azure函数简介 (Introduction to Azure Functions)

Azure Functions is the serverless platform offered by Microsoft, using which developers can write complex business logic and execute these without having to worry about the underlying infrastructure. Along with Azure Functions, Microsoft also offers two other serverless platforms, namely Logic Apps, a simple visual workflow manager that enables users to schedule, automate, orchestrate tasks within Azure and Event Grid, a service which helps users manage to the route of events from source to destination within the Azure cloud:

Azure Functions是Microsoft提供的无服务器平台,开发人员可以使用它来编写复杂的业务逻辑并执行它们,而不必担心基础架构。 微软与Azure Functions一起,还提供了另外两个无服务器平台,即Logic Apps,这是一个简单的可视化工作流管理器,使用户能够在Azure和Event Grid中计划,自动化或协调任务,该服务可帮助用户管理来自源到Azure云中的目标:

Introduction to Azure Functions

Azure Functions is the event-based serverless application framework which can automatically scale up and down based on the executions that are being triggered. This helps the developers and in turn the organizations to focus more on business logic and less DevOps time. This also helps less time for the organizations to ship these functions to the market as compared to other server-based applications. Azure Functions is ideal to write up any cron jobs, fetch data from an IoT device, get and transform data from any REST API, write data to Azure SQL Database or Cosmos DB, also mobile backends, etc.

Azure Functions是基于事件的无服务器应用程序框架,可以根据正在触发的执行情况自动放大和缩小。 这有助于开发人员,进而帮助组织将更多精力放在业务逻辑上,并减少DevOps时间。 与其他基于服务器的应用程序相比,这也减少了组织将这些功能推向市场的时间。 Azure Functions是编写任何cron作业,从IoT设备获取数据,从任何REST API获取和转换数据,将数据写入Azure SQL数据库或Cosmos DB以及移动后端等的理想选择。

As you can see in the figure above, Azure Functions is a combination of code and events. These functions are executed using triggers and also have bindings that help to run these events based on a pre-defined schedule, API calls, or any other file system triggers. To start with Azure Functions, all you need to do is to sign up for an Azure subscription by visiting https://portal.azure.com and then select Azure Functions.

如上图所示,Azure Functions是代码和事件的组合。 这些函数使用触发器执行,并且具有绑定,这些绑定有助于基于预定义的计划,API调用或任何其他文件系统触发器来运行这些事件。 要开始使用Azure Functions,您所需要做的就是通过访问https://portal.azure.com来注册Azure订阅,然后选择Azure Functions。

AWS Lambda概述 (Overview of AWS Lambda)

AWS Lambda is also a serverless compute service provided by Amazon. It is priced based on the duration of the execution of the function and the number of times it is being executed. Customers are charged only for the time during which the code is being run. AWS Lambda also provides support for multiple languages starting from C#, JavaScript, Python, etc. You can author the code in any text or code editor and then upload a zip folder of your code to the IDE in AWS Management Console.

AWS Lambda还是亚马逊提供的无服务器计算服务。 根据函数执行的持续时间和函数执行的次数来定价。 仅在代码运行期间向客户收费。 AWS Lambda还支持从C#,JavaScript,Python等开始的多种语言。您可以在任何文本或代码编辑器中编写代码,然后将代码的zip文件夹上载到AWS管理控制台中的IDE。

Below are a few events which can be used to trigger a lambda function:

以下是一些可用于触发lambda函数的事件:

  • When a table is updated in Amazon DynamoDB

    在Amazon DynamoDB中更新表时
  • When messages arrive from Amazon Kinesis Stream

    消息从Amazon Kinesis Stream到达时
  • When objects in AWS S3 are modified

    修改AWS S3中的对象时
  • When notifications are sent from Amazon SNS (Simple Notification System)

    从Amazon SNS(简单通知系统)发送通知时
  • When messages are added to Amazon SQS (Simple Queue Service)

    将消息添加到Amazon SQS(简单队列服务)时
  • When custom events are triggered by mobile apps, web apps, or any other service

    当移动应用程序,Web应用程序或任何其他服务触发自定义事件时

AWS Lambda – Serverless Applications

To begin writing code in AWS Lambda, you need to have a valid AWS account. You can sign up for AWS by visiting http://console.aws.amazon.com/ and use your email address to signup and start writing code with AWS Lambda.

要开始在AWS Lambda中编写代码,您需要拥有一个有效的AWS账户。 您可以通过访问http://console.aws.amazon.com/来注册AWS,并使用您的电子邮件地址进行注册并开始使用AWS Lambda编写代码。

Google Cloud功能概述 (Overview of Google Cloud Functions)

Cloud Functions from Google are also an offering using which developers can build serverless applications. Google has been in providing options for cloud computing since early 2008, with the launch of its Google App Engine. However, the Cloud Functions are a pretty recent addition, only in the year 2017. Like AWS Lambda and Azure Functions, Cloud Functions also support an event-driven approach to start the executions of the functions:

Google的Cloud Functions也是一种产品,开发人员可以使用它来构建无服务器应用程序。 自2008年初推出Google App Engine以来,Google一直在为云计算提供选项。 但是,仅在2017年才添加了Cloud Functions。与AWS Lambda和Azure Functions一样,Cloud Functions还支持事件驱动的方法来开始执行功能:

Google Cloud Functions

Few of the important use cases to begin with Cloud Functions are as follows:

从Cloud Functions开始的几个重要用例如下:

  • Process images and other data based on a pre-defined event

    根据预定义的事件处理图像和其他数据
  • Respond to events that are triggered via simple HTTP calls

    响应通过简单的HTTP调用触发的事件
  • It can be used to build light-weight APIs

    它可以用来构建轻量级的API
  • It can be used as a backend for mobile applications, using Firebase as a database

    可以将Firebase用作数据库,用作移动应用程序的后端
  • It can also be used to transform IoT data from live streams

    它还可以用于从实时流转换IoT数据

结论 (Conclusion)

In this article, we have seen what serverless applications are and the different cloud providers that offer us the ability to write code that can be deployed in the serverless frameworks they provide. Using such an architecture is beneficial for most of the developers as well as the organization as they can now focus more on the code and business logic and leave the infrastructure to the cloud provider. Also, these kinds of serverless applications are scalable on-demand, which means based on the load, they can add up resources, and when the load is less, it can easily free up the resources. This helps a lot to manage the pricing as the functions are charged only for the duration they are being executed and not for the entire time. Also, based on the resources being used, the pricing of the function may go up or down; however, it is cheaper than provisioning a full VM to deploy the function.

在本文中,我们了解了无服务器应用程序是什么,以及不同的云提供程序使我们能够编写可部署在它们提供的无服务器框架中的代码。 使用这种体系结构对大多数开发人员和组织都是有益的,因为他们现在可以将更多的精力放在代码和业务逻辑上,并将基础结构留给云提供商。 而且,这类无服务器应用程序可以按需扩展,这意味着基于负载,它们可以添加资源,而当负载较小时,可以轻松释放资源。 这对管理定价很有帮助,因为功能仅在执行期间而不是整个时间进行收费。 另外,根据使用的资源,功能的价格可能会上涨或下跌; 但是,它比配置完整的VM部署功能要便宜。

翻译自: https://www.sqlshack.com/an-introduction-to-serverless-applications/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值