aws lambda_简化sdk另一个强大的nodejs框架来管理aws lambda函数依赖项

aws lambda

When working with AWS services, you’ve got several choices to build and deploy your lambda functions: Serverless Framework, AWS Amplify Framework, and AWS SAM CLI are the three most popular toolkit today. Each of them has different pros and cons. The cons you will get just happens after your project sized to be a complex solution beyond their pre-designed, intended purpose. In this article, I want to introduce yet another choice for your work with less locked-in, highly customization, and ultimate control of your Infrastructure as Code solution.

今天无服务器架构,AWS中扩增框架和AWS SAM CLI是三个最流行的工具:与AWS服务W¯¯母鸡的工作,你有多种选择,以构建和部署lambda函数。 他们每个人都有各自的优缺点。 在您的项目规模超出其预先设计的预期目的而成为一个复杂的解决方案之后,您会遇到的弊端就是如此。 在本文中,我想为您的工作介绍另一种选择,即减少锁定,高度自定义并最终控制基础架构即代码解决方案。

What is Simplify-SDK? This is a JavaScript SDK that helps your DevOp integration easier by adding deployment steps inline to your project solution. You will never want to be locked into any vendor for a tool you use. In FaaS architecture, a function can be very small but a project needs some (3–100) functions to orchestrate a workload. One CI/CD tool for all of them is quite hard to deploy your project when you just need to manage a stand-alone function.

什么是Simplify-SDK? 这是一个JavaScript SDK,可通过在项目解决方案中内联添加部署步骤来帮助您轻松进行DevOp集成。 您将永远不会想要使用的工具锁定任何供应商。 在FaaS架构中,功能可能很小,但是项目需要一些(3-100)功能来协调工作量。 当您只需要管理独立功能时,针对所有这些工具的一个CI / CD工具就很难部署。

According to this intention of purpose, Simplify-SDK is built for creating new infrastructure as AWS resources, managing Lambda functions and its configuration, monitoring them by writing your infrastructure management tool using your favourite JavaScript language with Node runtime. For a basic understanding of how to use this SDK, here is a “Hello World” example:

根据此目的,构建Simplify-SDK的目的是创建新的基础架构作为AWS资源,管理Lambda函数及其配置,并通过使用喜欢JavaScript语言和Node runtime编写基础结构管理工具来监视它们。 为了基本了解如何使用此SDK,下面是一个“ Hello World”示例:

Given you have an existing Lambda function that was already deployed by a Serverless YML definition with the StackOutput parameters:

假设您有一个现有的Lambda函数,该函数已经由具有StackOutput参数的无服务器YML定义部署:

  • Lambda Function Name: — “YourLambdaFunction-1WDRZ5J5OUN5H”

    Lambda函数名称:—“ YourLambdaFunction-1WDRZ5J5OUN5H”

  • Lambda Function Role ARN: — “arn:aws:iam::01234567890:role/YourLambdaExecutionRole”

    Lambda函数角色ARN:—“ arn:aws:iam :: 01234567890:role / YourLambdaExecutionRole”

Serverless organizes your code with a repo base concept with single Code Base, one Resource Stack and one Policy. Here is your project structure of a FaaS architecture organized within one repo:

Serverless通过一个带有单个代码库,一个资源栈和一个策略的存储库概念来组织代码。 这是在一个仓库中组织的FaaS架构的项目结构:

aws lambda_简化sdk另一个强大的nodejs框架来管理aws lambda函数依赖项_第1张图片
Figure — 2: A typical serverless project structure. 图2:典型的无服务器项目结构。

There are two new files: config.json and deploy.js that do not belong to Serverless Framework and will be added in the next steps of this article.

有两个新文件:config.json和deploy.js不属于Serverless Framework,将在本文的后续步骤中添加。

After months of a project growing, you don’t want to update your function using serverless deploy function -f command. One of your reasons will be serverless uploads your function code using a single distribution package with all repo code. The other hand, it uses one single AWS Role Policy per repo for every function. Instead of that design, you want to design a function by your way; with extended management capability — for example; you must restrict your function resource access with an individual Role Policy, you want to minimize your function code just deploy a partial code what they need to overcome Cold Start bootstrap issue, or to extend the other security measures etc, those things are hard to be done by just using Serverless Framework.

在项目增长了几个月之后,您不想使用serverless deploy function -f命令来更新功能。 原因之一是无服务器使用包含所有回购代码的单个分发包来上载功能代码。 另一方面,它为每个功能使用每个仓库一个单一的AWS角色策略。 除了设计之外,您还想通过自己的方式设计功能。 具有扩展的管理能力-例如; 您必须使用单独的角色策略限制功能资源的访问,要最大程度地减少功能代码,而只是部署部分代码以解决冷启动引导问题或扩展其他安全措施等,这些事情很难做到只需使用无服务器框架即可完成。

To do so, Simplify-SDK which is distributed as a node package must be installed by using npm or yarn as your choice (use one of them):

为此,必须通过使用npm或yarn选择安装(作为节点软件包分发)的Simplify-SDK(使用其中之一):

  • npm install simplify-sdk

    npm install simple-sdk

  • yarn add simplify-sdk

    纱线添加简化-SDK

To give the framework knowing about your deployment environment, a generic configuration is created to declare what you intend to do with your function and other resources. Here is an example of config.json:

为了使框架了解您的部署环境,将创建一个通用配置,以声明您打算对功能和其他资源进行的操作。 这是config.json的示例:

aws lambda_简化sdk另一个强大的nodejs框架来管理aws lambda函数依赖项_第2张图片

In this configuration, it allows you passing variables from your code or ENVIRONMENT variables (ex: process.env.VAR) into the brackets syntax placeholders — ${VAR} that was declared in config.json. The Function block of this file is the parameter input following the definition of AWS Lambda updateFunctionCode:

在此配置中,它允许您将代码中的变量或环境变量(例如:process.env.VAR)传递到方括号语法占位符—在config.json中声明的$ {VAR}。 该文件的Function块是遵循AWS Lambda updateFunctionCode定义的参数输入:

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#updateFunctionCode-property

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#updateFunctionCode-property

Now, it’s time to write your infrastructure as NodeJS code:

现在,是时候将您的基础结构编写为NodeJS代码了:

You can find this example code at https://github.com/simplify-framework/simplify repository by README document.

您可以在README文档的https://github.com/simplify-framework/simplify存储库中找到此示例代码。

Finally, to update your function code, just get into your function location and run this code:

最后,要更新功能代码,只需进入功能位置并运行以下代码:

cd functions/YourLambdaFunction && node deploy.js

cd函数/ YourLambdaFunction &&节点deploy.js

Or adding this command line into your package.json:

或将此命令行添加到package.json中:

Image for post

Simplify-SDK supports these functions to manage AWS infrastructure such as creating your very complex CloudFormation stack, linking between serverless and another CloudFormation resource or managing AWS Resource Policy:

Simplify-SDK支持以下功能来管理AWS基础设施,例如创建非常复杂的CloudFormation堆栈,在无服务器资源和另一CloudFormation资源之间进行链接或管理AWS Resource Policy:

Checkout Simplify Framework for more than what you need!

Checkout Simplify Framework满足您的需求!

Follows my articles:

跟随我的文章:

Publishing a TensorFlow Model on AWS Lambda to make a sell-able APIDIY — Build Yourself a Serverless Framework with 152 Lines of CodeThe On-Demand Wakeup Pattern to Overcome AWS Lambda Cold Start

在AWS Lambda上发布TensorFlow模型以制作可出售的API DIY —使用152行代码构建无服务器框架, 按需唤醒模式可克服AWS Lambda冷启动

翻译自: https://medium.com/problem-solving-blog/simplify-sdk-another-powerful-nodejs-framework-to-manage-your-aws-lambda-functions-dependency-65b1931d28b5

aws lambda

你可能感兴趣的:(python,java,nodejs,vue,spring)