简体   繁体   English

您如何运行(“调用”)AWS Lambda函数?

[英]How do you run ('invoke') an AWS lambda function?

I have written and saved a lambda function. 我已经编写并保存了一个lambda函数。 I see: 我懂了:

Congratulations! 恭喜! Your Lambda function "lambda_name" has been successfully created. 您的Lambda函数“ lambda_name”已成功创建。 You can now change its code and configuration. 现在,您可以更改其代码和配置。 Choose Test to input a test event when you want to test your function. 要测试功能时,选择“测试”以输入测试事件。

Now how do I run it? 现在如何运行它? I cannot see a 'run' or 'invoke' button as I would expect 我看不到预期的“运行”或“调用”按钮

Note 注意

The lambda doesn't accept any arguments (it's extremely simple - for the purposes of this question, please presume it's simply 2 * 2 so when I run it it should not require any inputs and should return 4). lambda不接受任何参数(这非常简单-就此问题而言,请假定它只是2 * 2因此在我运行它时,它不需要任何输入并应返回4)。

Also note 另请注意

I can see a tonne of different ways to run the lambda here . 我可以在这里看到多种运行lambda的不同方式。 I just want the simplest way (preferably a button in the browser) 我只想要最简单的方法(最好是浏览器中的按钮)

Sending a test message via the Lambda console will run your Lambda function. 通过Lambda控制台发送测试消息将运行您的Lambda函数。 The test message that you configure will define what is in the event parameter of your lambda handler function. 您配置的测试消息将定义lambda处理函数的event参数中的内容。

在此处输入图片说明

Since you are not doing anything with that message, you can send any arbitrary test message and it should work for you. 由于您对该消息不做任何事情,因此可以发送任意测试消息,它应该对您有用。 You can just use the default hello world message and give it an arbitrary name. 您可以只使用默认的hello world消息并为其指定一个任意名称。

It should then show you the results: any logs or returned objects right in the AWS Lambda console. 然后它将向您显示结果:AWS Lambda控制台中的所有日志或返回的对象。

Further reading here 在这里进一步阅读

AWS Lambda functions are typically triggered by an event, such as an object being uploaded to Amazon S3 or a message being send to an Amazon SNS topic. AWS Lambda函数通常由事件触发 ,例如将对象上载到Amazon S3或将消息发送到Amazon SNS主题。

This is because Lambda functions are great at doing a small task very often . 这是因为Lambda函数非常擅长于经常执行小任务 Often, Lambda functions only run for a few seconds, or even less than a second! 通常,Lambda函数只能运行几秒钟,甚至不到一秒钟! Thus, they are normally triggered in response to something else happening. 因此,它们通常是响应其他情况而触发的。 It's a bit like when somebody rings your phone, which triggers you to answer the phone. 这有点像有人打您的电话,这会触发您接听电话。 You don't normally answer your phone when it isn't ringing. 当电话不响时,您通常不会接听电话。

However, it is also possible to directly invoke an AWS Lambda function using the Invoke() command in the AWS SDK. 但是,也可以使用AWS开发工具包中的Invoke()命令直接调用AWS Lambda函数 For convenience, you can also use the AWS Command-Line Interface (CLI) aws lambda invoke command. 为方便起见,您还可以使用AWS命令行界面(CLI) aws lambda invoke命令。 When directly invoking an AWS Lambda function, you can receive a return value. 直接调用AWS Lambda函数时,您会收到一个返回值。 This is in contrast to situations where a Lambda function is triggered by an event, in which case there is nowhere to 'return' a value since it was not directly invoked. 这与Lambda函数由事件触发的情况形成对比,在这种情况下,由于没有直接调用值,因此无处“返回”值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM