官术网_书友最值得收藏!

  • 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.

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:

  1. 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
  1. 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
  1. 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!

主站蜘蛛池模板: 亳州市| 博乐市| 东兴市| 乐业县| 蛟河市| 准格尔旗| 个旧市| 额尔古纳市| 安福县| 南宫市| 隆尧县| 吉木乃县| 新和县| 小金县| 塔城市| 元江| 永顺县| 儋州市| 沧源| 许昌市| 内丘县| 竹北市| 措勤县| 台中市| 娱乐| 包头市| 岗巴县| 云浮市| 永仁县| 繁峙县| 峨眉山市| 黄大仙区| 梁山县| 江北区| 临沧市| 唐河县| 商水县| 南投市| 祁连县| 长治市| 东乡|