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

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

主站蜘蛛池模板: 江安县| 云安县| 张家港市| 邹城市| 河东区| 南阳市| 金秀| 刚察县| 右玉县| 怀远县| 开远市| 兴海县| 翁牛特旗| 洪湖市| 景泰县| 文化| 盖州市| 深泽县| 连南| 武功县| 沙坪坝区| 千阳县| 呈贡县| 黎平县| 南岸区| 高淳县| 抚顺市| 靖西县| 泌阳县| 霍林郭勒市| 上栗县| 离岛区| 元谋县| 抚顺市| 济源市| 芜湖市| 石阡县| 留坝县| 土默特左旗| 平果县| 灌云县|