- DevOps for Serverless Applications
- Shashikant Bangera
- 273字
- 2021-07-16 17:35:35
Functions and events
Functions are the properties that are defined within the service, and they are defined within the serverless.yml, so we name the function and provide the handler property to the function, and this property points to the function file, which could be Node.js or Python. We can add multiple functions within the property. The functions can inherit the properties from the provider or we can define the properties at function level. These function properties vary as per the cloud provider, as shown in the following code:
# serverless.yml
service: myService
provider:
name: aws
runtime: nodejs6.10
memorySize: 512 # will be inherited by all functions
functions:
usersAdd:
handler: handler.userAdd
description: optional description for your function
userModify:
handler: handler.userModify
userDelete:
handler: handler.userDelete
memorySize: 256 # function specific
The functions can be listed as arrays if we create a separate file for each function:
# serverless.yml
functions:
- ${file(../user-functions.yml)}
- ${file(../post-functions.yml)}
# user-functions.yml
addUser:
handler: handler.user
deleteUser:
handler: handler.user
An environment object property can also be added to the function within the service, and it should be a key–pair value. Also, the function-specific environment variable overrides the provider-specific environment variable:
# serverless.yml
service: service-name
provider: aws
functions:
hello:
handler: handler.hello
environment:
TABLE_NAME: tableName
Events are things that trigger the function, such as the S3 bucket upload. There are multiple events supported by Serverless Framework, but they vary as per the cloud provider. We can define multiple events for a single function, as shown in the following code:
events:
- http:
path: handler
method: get
https://serverless.com/framework/docs/providers/aws/events/
- Kubernetes修煉手冊
- Containerization with LXC
- Hands-On DevOps with Vagrant
- Windows Server 2012 Hyper-V Cookbook
- Ganglia系統(tǒng)監(jiān)控
- SharePoint 2013 應(yīng)用開發(fā)實(shí)戰(zhàn)
- Java EE 8 Design Patterns and Best Practices
- Linux系統(tǒng)安全基礎(chǔ):二進(jìn)制代碼安全性分析基礎(chǔ)與實(shí)踐
- 細(xì)說Linux基礎(chǔ)知識
- VMware Horizon View Essentials
- Linux網(wǎng)絡(luò)操作系統(tǒng)項(xiàng)目教程(RHEL 7.4/CentOS 7.4)(第3版)(微課版)
- Linux集群之美
- Raspberry Pi入門指南
- 應(yīng)急指揮信息系統(tǒng)設(shè)計
- Learning Joomla! 3 Extension Development(Third Edition)