上QQ阅读APP看书,第一时间看更新
Function code
Here, you are required to write the code. The Lambda function has a predefined pattern for writing the code. While writing the code, you need to understand the context. Lambda provides three kinds of feasibility, which decides your runtime execution for the code:
- Code entry type: This section provides three options to decide the entry type for your code, such as editing code inline, uploading a ZIP file, and uploading a file from Amazon S3.
- Runtime: This section provides options to decide the runtime programming language context for your code, such as Python, C#, NodeJS, and Java.
- Handler: A handler defines the path to your method/function, such as <filename>.<method_name>. For example, if you want to execute a function named as a handler, which is defined in main.py, then it would be main.handler.
Let's get back to our newly created hello world function named lambda_handler.
Here, the handler value is defined as lambda_function.lambda_handler, where lambda_function.py is the filename and lambda_handler is the method name:
def lambda_handler(event, context): print("value1 = " + event['key1']) print("value2 = " + event['key2'])
Lambda_handler accepts two positional arguments, event and context:
- event: This argument contains event-related information. For example, if we configure the Lambda function with Amazon S3 bucket events, then we would get S3 bucket information in event arguments, such as bucket name, region, and so on.
- context: This argument contains the context-related information that may be required during runtime for code execution.