aws lambda_AWS Lambda和Node js

aws lambda

什么是AWS LAMBDA? (What is AWS LAMBDA?)

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes the 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 the code is not running.

AWS Lambda是一种计算服务,可让您运行代码而无需置备或管理服务器。 AWS Lambda仅在需要时执行代码并自动扩展,从每天几个请求到每秒数千个。 您只需为您消耗的计算时间付费-代码未运行时不收费。

让我们深入研究lambda设置。 (Let’s Dive into the lambda setup.)

Prerequisite :

先决条件:

  1. AWS Account.

    AWS账户。
  2. Familiar with IAM Role.

    熟悉IAM角色。

Log on to AWS -> SERVICES -> LAMBDA

登录到AWS->服务-> LAMBDA

Image for post
  1. Click on the hamburger menu on the left-hand side.

    单击左侧的汉堡菜单。
  2. Click on Functions.

    单击功能。
  3. Click on Create Function which will be on the right-hand side.

    单击右侧的创建函数。
Image for post

4. Then the page redirects to.

4.然后页面重定向到。

Image for post

5. Choose A name for your function I am choosing “demoFunction”.

5.为您的函数选择一个名称我正在选择“ demoFunction”。

6. Click on Create Function.

6.单击创建功能。

7. The next page redirected will look similar to this.

7.重定向的下一页将与此类似。

Image for post

8. There will be functional and Environment variables sections below.

8.下面将有功能和环境变量部分。

Image for post

In the functional Code section, we can add our node js code for lambda.

在功能性代码部分,我们可以为lambda添加节点js代码。

In the handler function, the triggered events are available. data properties received it lambda will be available in events inside the handler function.

处理程序功能中,触发的事件可用。 lambda接收到的数据属性将在处理函数中的事件中提供。

如果lambda函数中需要其他npm软件包。 我们可以做到以下几点。 (If other npm packages are required in the lambda function. We can do the following.)

  1. Upload zipped node js project either form local or can be imported from S3.

    可以从本地上传压缩的节点js项目,也可以从S3导入。
Image for post

2. Add layers to the lambda services which can be used to all lambda functions.

2.将层添加到可用于所有lambda函数的lambda服务。

sadfasd

Click on layers and click on create layer

单击图层,然后单击创建图层

Image for post

To upload a package we need to have a Nodejs project will all dependencies in package.json and node_modules file.Zip it and upload it. It can be also done by importing files from S3 if the dependencies file exceeds 10 MB.

要上传一个包,我们需要有一个Nodejs项目将所有依赖项都放在package.json和node_modules文件中,然后将其压缩并上传。 如果依赖项文件超过10 MB,也可以通过从S3导入文件来完成。

用于存储功能中使用的秘密密钥或触发点的环境变量。 (Environmental Variables used to store secret keys or trigger points used in the functions.)

Image for post

我们甚至可以为lambda函数添加触发器。 示例每当将消息推送到SQS或将任何数据写入Dynamo DB时。 (We can even add triggers for our lambda functions. Example Whenever a message is pushed into SQS or if any data is written into Dynamo DB.)

Image for post

References: https://stackify.com/aws-lambda-with-node-js-a-complete-getting-started-guide/

参考: https : //stackify.com/aws-lambda-with-node-js-a-complete-getting-started-guide/

Thanks.

谢谢。

翻译自: https://medium.com/@manjunathajoshi/aws-lambda-and-node-js-96cf8f2b3ee4

aws lambda

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值