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

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!

主站蜘蛛池模板: 宽城| 淮北市| 承德县| 扬州市| 临沭县| 蚌埠市| 根河市| 邳州市| 晋州市| 陇川县| 金华市| 丰都县| 金堂县| 龙山县| 德保县| 霍城县| 沛县| 甘谷县| 昭苏县| 南郑县| 乌拉特前旗| 五莲县| 宜川县| 加查县| 青神县| 嘉禾县| 凤阳县| 平阴县| 齐齐哈尔市| 合水县| 句容市| 敦煌市| 鄢陵县| 葵青区| 高州市| 瓦房店市| 珠海市| 琼结县| 肇州县| 江川县| 申扎县|