- Building Serverless Python Web Services with Zappa
- Abdulwahid Abdulhaque Barguzar
- 242字
- 2021-07-16 18:16:08
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.
推薦閱讀
- Cisco OSPF命令與配置手冊
- Building E-commerce Sites with VirtueMart Cookbook
- Truffle Quick Start Guide
- 2018網(wǎng)信發(fā)展報告
- Getting Started with Grunt:The JavaScript Task Runner
- 網(wǎng)管員必讀:網(wǎng)絡(luò)管理(第2版)
- OMNeT++與網(wǎng)絡(luò)仿真
- Bonita Open Solution 5.x Essentials
- 6G無線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)
- 云計算技術(shù)與標準化
- 華為HCIA-Datacom認證指南
- 智能物聯(lián)網(wǎng):區(qū)塊鏈與霧計算融合應(yīng)用詳解
- 一本書讀懂移動物聯(lián)網(wǎng)
- 巧學(xué)活用CISCO網(wǎng)絡(luò)典型配置
- 物聯(lián)網(wǎng):感知、傳輸與應(yīng)用