Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding input in scheduled events in the serverless framework?

I am trying to pass some 'inputs' into my lambda function on a specific event and am researching ways of doing it. The serverless documentation shows examples of defining an input like such:

serverless.yml

functions:
  aggregate:
    handler: statistics.handler
    events:
      - schedule:
          rate: rate(10 minutes)
          enabled: false
          input:
            key1: value1
            key2: value2
            stageParams:
              stage: dev

I am still unsure what exactly this is and how it can be accessed (if at all) from my handlers.js function.

If someone could de-mystify this, it would be highly appreciated.

like image 952
Oamar Kanji Avatar asked Jan 29 '19 20:01

Oamar Kanji


People also ask

How do you trigger http events in serverless?

HTTP Trigger Azure Functions has an API endpoint created for each Function App. This service allows you to define public HTTP endpoints for your serverless functions. To create HTTP endpoints as Event sources for your Azure Functions, use the Serverless Framework's easy HTTP Events syntax.

How do I pass an environment variable in serverless?

To reference environment variables, use the ${env:SOME_VAR} syntax in your serverless. yml configuration file. It is valid to use the empty string in place of SOME_VAR . This looks like " ${env:} " and the result of declaring this in your serverless.

What are the features of Serverless Framework?

A Serverless app can simply be a couple of lambda functions to accomplish some tasks, or an entire back-end composed of hundreds of lambda functions. Serverless supports all runtimes offered within the cloud provider chosen. Serverless is developed by Austen Collins and maintained by a full-time team.

What are events in lambda function?

An event is a JSON-formatted document that contains data for a Lambda function to process. The Lambda runtime converts the event to an object and passes it to your function code. It is usually of the Python dict type. It can also be list , str , int , float , or the NoneType type.


1 Answers

These values will be passed to your lambda function as part of event object.

nodejs lambda code:

exports.handler = (event, context, callback) =>{
  console.log("key1 is", event.key1)
  return 0
}
like image 161
Prabhat Avatar answered Sep 30 '22 17:09

Prabhat