- Serverless Design Patterns and Best Practices
- Brian Zambrano
- 359字
- 2021-08-27 19:12:06
Wiring handler.py to Lambda via API Gateway
Next, we need to wire up our API endpoints to Lambda and our handler.py entry point. This wiring looks like this in a serverless.yml configuration file:
functions:
HandleSession:
handler: handler.session
events:
- http:
path: session
method: get
cors: true
- http:
path: session
method: post
cors: true
HandleSessionDetail:
handler: handler.session_detail
events:
- http:
path: session/{id}
method: get
cors: true
request:
parameters:
paths:
id: true
- http:
path: session/{id}
method: delete
cors: true
request:
parameters:
paths:
id: true
We define two Lambda functions that have different configuration options, HandleSession and HandleSessionDetail.
Under each function's name, there are multiple statements that control configuration. Look at both sections and you'll notice the handler: statement, which instructs Lambda what code to call when the Lambda function is executed. For both, we'll be running one of the Python functions in handler.py that we covered in the preceding code snippet.
But what calls these Lambda functions in the first place? The events: section is responsible for setting up invocation points and making the connection between a particular event and our Lambda function. Across the FaaS landscape, functions are invoked in response to an event. In the AWS landscape, the number of events that can trigger a Lambda function is quite large. In this scenario, we are configuring events to be HTTP endpoints with a particular path and HTTP method. API Gateway is the proxy that will provide us with unique HTTPS URLs, which get wired up to our Lambda functions according to our configuration. As you read through the configuration, our design and intent should be apparent. Again, there are a seemingly infinite number of ways to set up an API with these technologies and this example just scratches the surface to discuss the overall pattern.
- 虛擬儀器設計測控應用典型實例
- 集成架構中型系統
- 人工智能超越人類
- 嵌入式系統應用
- R Machine Learning By Example
- TIBCO Spotfire:A Comprehensive Primer(Second Edition)
- 西門子S7-200 SMART PLC從入門到精通
- TestStand工業自動化測試管理(典藏版)
- 計算機原理
- 電腦上網直通車
- 21天學通Visual C++
- Implementing Splunk 7(Third Edition)
- 愛犯錯的智能體
- MATLAB/Simulink權威指南:開發環境、程序設計、系統仿真與案例實戰
- OpenStack Cloud Computing Cookbook