stevec
stevec

Reputation: 52198

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

I have written and saved a lambda function. I see:

Congratulations! Your Lambda function "lambda_name" has been successfully created. 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).

Also note

I can see a tonne of different ways to run the lambda here. I just want the simplest way (preferably a button in the browser)

Upvotes: 1

Views: 3221

Answers (2)

JD D
JD D

Reputation: 8087

Sending a test message via the Lambda console will run your Lambda function. The test message that you configure will define what is in the event parameter of your lambda handler function.

enter image description here

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.

It should then show you the results: any logs or returned objects right in the AWS Lambda console.

Further reading here

Upvotes: 3

John Rotenstein
John Rotenstein

Reputation: 269091

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.

This is because Lambda functions are great at doing a small task very often. Often, Lambda functions only run for a few seconds, or even less than a second! 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. For convenience, you can also use the AWS Command-Line Interface (CLI) aws lambda invoke command. When directly invoking an AWS Lambda function, you can receive a return value. 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.

Upvotes: 2

Related Questions