- 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.
- 大學(xué)計(jì)算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- 數(shù)控銑削(加工中心)編程與加工
- Associations and Correlations
- AWS Certified SysOps Administrator:Associate Guide
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- CompTIA Network+ Certification Guide
- CompTIA Linux+ Certification Guide
- 工業(yè)機(jī)器人運(yùn)動(dòng)仿真編程實(shí)踐:基于Android和OpenGL
- 貫通Java Web開(kāi)發(fā)三劍客
- Windows Server 2008 R2活動(dòng)目錄內(nèi)幕
- 會(huì)聲會(huì)影X4中文版從入門到精通
- Mastering Exploratory Analysis with pandas
- 重估:人工智能與賦能社會(huì)
- Hands-On Business Intelligence with Qlik Sense
- 智能+:制造業(yè)的智能化轉(zhuǎn)型