用aws服务器部署邮件_AWS无服务器部署101

用aws服务器部署邮件

AWS Lambda is the compute service under the AWS Serverless ecosystem. For development and deployment of Lambda function along with the infrastructure it needs, one tends to use development frameworks. Two of the most popular frameworks used for this purpose are —

AWS Lambda是AWS无服务器生态系统下的计算服务。 为了开发和部署Lambda功能以及所需的基础结构,人们倾向于使用开发框架。 用于此目的的两个最受欢迎的框架是-

  1. AWS Serverless Application Model (SAM)

    AWS无服务器应用程序模型(SAM)
  2. Serverless Framework

    无服务器框架

Assuming you are using AWS SAM, initializing a green field Hello World Lambda function with SAM CLI (tool that operates on an AWS SAM template and application code) is a three-step process:

假设您使用的是AWS SAM,则使用SAM CLI( 在AWS SAM模板和应用程序代码上运行的工具)初始化绿色字段Hello World Lambda函数的过程分为三个步骤:

Step 1 > sam initIn this step, you get the option to select runtime for the Lambda function, provide service name and few other options depending on the runtime selected. Once done, you get a folder structure with basic resources created.

The Hello World Function inside the template file looks as below:

模板文件中的Hello World函数如下所示:

Image for post
Hello World Resource in Template File
模板文件中的Hello World资源
Step 2 > sam package --s3-bucket <bucket name>In this step, the application code and dependencies are bundled into a deployment package and is pushed to S3 bucket. And generates a Yaml template file as output.
Image for post
sam package console output sam软件包控制台输出
Step 3 > sam deploy --template-file package.yaml --stack-name hello-world --capabilities CAPABILITY_IAMIn this step, the lambda function and other infrastructure resources gets deployed via SAM template which gets converted to CloudFormation stack.
Image for post
sam deploy console output sam部署控制台输出

Every time the sam deploy command is issued, SAM template gets translated to CloudFormation template, and it eventually publishes the new version of the Hello World Function. This new version is tagged as $LATEST.

每次发出sam deploy命令时 ,SAM模板都会转换为CloudFormation模板,并最终发布新版本的Hello World Function。 此新版本标记为$ LATEST。

Image for post
Hello World Lambda Function in AWS Console
AWS控制台中的Hello World Lambda函数

With this deployment, any new request coming for the Hello World function is handled by the latest version of the lambda. And all existing running instances of Hello World function gets terminated. Cool!!!

通过此部署,最新版本的lambda将处理对Hello World函数的任何新请求。 并且所有现有的Hello World函数正在运行的实例都将终止。 凉!!!

But what if the new function has got some bug in it which could not be captured in the early stages of Unit testing and Integration testing. All your traffic will be impacted, and User Experience will go for a toss 😩.

但是,如果新功能出现一些错误,而该错误在单元测试和集成测试的早期阶段无法捕获,该怎么办? 您的所有访问量都会受到影响,并且用户体验会受到影响

We can handle such issues by following the Blue Green deployment strategy. It helps to increase the availability of the system and reduce risk associated with deployment.

我们可以通过遵循“蓝绿色”部署策略来处理此类问题。 它有助于提高系统的可用性并降低与部署相关的风险。

In this strategy, we can have 2 versions of the function running at the same time and traffic can be diverted to the latest version in an incremental fashion.

在这种策略中,我们可以同时运行两个版本的功能,并且可以以递增的方式将流量转移到最新版本。

AWS SAM supports multiple traffic dialing strategies out of box.

AWS SAM开箱即用地支持多种流量拨号策略。

  1. Canary — Traffic is shifted in two increments from old version to new version

    金丝雀 -流量从旧版本到新版本以两种增量转移

  2. Linear — Traffic is shifted from old version to new version in equal increments with an equal number of minutes between each increment.

    线性 -流量以相同的增量从旧版本转移到新版本,每次增量之间的分钟数相等。

To use the Blue/Green option, SAM template has two attributes which needs to be configured in the Lambda function —

要使用“蓝色/绿色”选项,SAM模板具有两个属性,需要在Lambda函数中进行配置-

  1. AutoPublishAlias — AWS SAM manages the traffic distribution by creating an Alias with the name specified and assigns the percentage of traffic to be distributed between new version and old version depending on the deployment preference type mentioned below.

    AutoPublishAlias — AWS SAM通过创建具有指定名称的别名来管理流量分配,并根据下面提到的部署首选项类型分配要在新版本和旧版本之间分配的流量百分比。

  2. Deployment Preference Type — Dictates how distribution of traffic between new and old version is to be handled.

    部署首选项类型 -决定如何处理新旧版本之间的流量分配。

Some of the pre-configured deployment preference type are available out of box —

一些预先配置的部署首选项类型是开箱即用的-

Canary10Percent30Minutes
Canary10Percent5Minutes
Canary10Percent10Minutes
Canary10Percent15Minutes
Linear10PercentEvery10Minutes
Linear10PercentEvery1Minute
Linear10PercentEvery2Minutes
Linear10PercentEvery3Minutes

Let’s say we want to route 10 % of the production traffic incrementally to new Lambda version every 1 minute. To configure this, the Hello World Lambda Function will look something as below —

假设我们希望每1分钟将10%的生产流量逐步路由到新的Lambda版本。 要进行配置,Hello World Lambda函数将如下所示—

Image for post
Hello World Lambda with Blue/Green Deployment Strategy
蓝/绿部署策略的Hello World Lambda

When sam deploy command is issued with the above changes, AWS SAM internally configures AWS Code Deploy (another AWS Serverless service for deploying the code and managing the traffic distribution using Blue/Green pattern) application which manages the traffic dialing.

当发出具有上述更改的sam deploy命令时,AWS SAM在内部配置管理流量拨号的AWS Code Deploy( 另一个用于部署代码并使用Blue / Green模式管理流量分配的AWSless Server服务 )应用程序。

This is how it looks like in the AWS Code Deploy console when the deploy command is issued —

发出deploy命令时,在AWS Code Deploy控制台中是这样的-

Image for post
AWS Code Deploy Console with Linear Blue/Green Deployment
具有线性蓝/绿部署的AWS Code Deploy控制台

You can also configure Cloud Watch Alarms which if triggered can roll back the deployment process.

您还可以配置Cloud Watch Alarms,如果触发,则可以回滚部署过程。

As part 2 of this blog, will have an actual Serverless Micro service implemented with Lambda and configured with end to end CI/CD DevOps process using AWS Development tools — AWS Code Commit, AWS Code Build, AWS Code Deploy and AWS Code Pipeline.

作为此博客的第2部分,将使用Lambda实现一个实际的无服务器微服务,并使用AWS开发工具(AWS Code Commit,AWS Code Build,AWS Code Deploy和AWS Code Pipeline)端到端CI / CD DevOps流程进行配置。

Till then, Cheers!!!

直到那时,干杯!!!

翻译自: https://medium.com/@waswani/aws-serverless-deployment-101-b8917bae137f

用aws服务器部署邮件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值