- Practical Site Reliability Engineering
- Pethuru Raj Chelliah Shreyash Naithani Shailender Singh
- 349字
- 2021-06-10 19:08:09
Example 3 – the Serverless deployment tool
Serverless is widely used by enterprises working in this domain. We have provided examples of both Apex and Serverless for your reference. Make sure Serverless is installed, and then install the Serverless command-line. We can then call it using Serverless or using the alias name of the sls command.
Check for the Serverless configuration file at: https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/aws-python.
There are two important files that you have to configure while working with the Serverless command:
- serverless.yml: This contains details about how to deploy the serverless function. This file is used by the sls/serverless command.
- handler.py: This file contains the actual function code. Your function will be defined here.
The sls command can be used as a shortcut for serverless as shown here:
$ sls
The following steps demonstrate how to create and deploy a service using the Serverless tool:
- Create a service: This command is used to create a service template so that we can write our functionality. With the sls create command, we can specify aws-python, among other available templates. In this example, we are going to use aws-python with the --template or shorthand -t flag. The --path or shorthand -p is used to update the path where the template service file will be created:
# sls create --template aws-python --path my-service
- Deploy the function: The following code will deploy the function to AWS Lambda based on the configuration that you created in the serverless.yml file:
# sls deploy
- Invoke the deployed function: The sls invoke command is used run the function. The -- function or the shorthand -f can be used to mention the function name:
# sls invoke -f hello
In your Terminal window, you should see the following response from AWS Lambda:
{
"status Code": 200,
"body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":{}}"
}
Congratulations! You have now deployed and run your first Hello World function!
推薦閱讀
- Splunk 7 Essentials(Third Edition)
- Hands-On Internet of Things with MQTT
- Dreamweaver CS3網頁制作融會貫通
- 傳感器與新聞
- 網中之我:何明升網絡社會論稿
- Deep Reinforcement Learning Hands-On
- 激光選區熔化3D打印技術
- 嵌入式Linux系統實用開發
- Building Google Cloud Platform Solutions
- Photoshop CS4數碼照片處理入門、進階與提高
- 工業機器人操作
- 軟件測試管理
- 電氣自動化工程師自學寶典(基礎篇)
- 洞察大數據價值:SAS編程與數據挖掘
- 局域網組建與使用完全自學手冊