AWS Lambda_handler

ewillwin·2022년 6월 20일
0

TSMtech Record

목록 보기
2/39

Lambda function handler is the method in your function code that processes events.
-> 함수가 호출되면 Lambda는 handler method를 실행함 (main 함수 느낌?)
-> When the handler exits or returns a response, it becomes available to handle another event.

def handler_name(event, context): 
    ...
    return some_value

일반적인 function handler의 syntax

function handler의 default name: lambda_function.lambda_handler

How it works

When Lambda invokes your function handler, the Lambda runtime passes two arguments to the fucntion handler

  • The first argument is the event object. 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.
  • The event object contains information from the invoking service. When you invoke a function, you determine the structure and contents of the event. When an AWS service invokes your function, the service defines the event structure.
  • The second argument is the Context object. A context object is passed to your function by Lambda at runtime. This object provides methods and properties that provide information about the invocation, function, and runtime environment.

Returning a value

Optionally, a handler can return a value. What happens to the returned value depends on the invocation type and the service that invoked the function. For example,

  • If you use the RequestResponse invocation type, AWS Lambda returns the result of the Python function call to the client invoking the Lambda function (in the HTTP response to the invocation request, serialized into JSON).
  • If the handler returns objects that can't be serialized by json.dumps, the runtime returns an error.
  • If the handler returns None, as Python functions without a return statement implicitly do, the runtime returns null.
  • If you use an Event an Asynchronous invocation invocation type, the value is discarded.
profile
Software Engineer @ LG Electronics

0개의 댓글