You can use the custom runtime of Function Compute to write functions in Function Compute by using PowerShell 7.1. This topic describes how to deploy and invoke a PowerShell function. You can modify the Powershell sample code to perform secondary development.


The following operations are complete:


  1. Run the following command in the target directory to initialize the project:
    s init start-fc-custom-samples -d start-fc-custom-samples
  2. Run the following command to go to the project directory:
    cd start-fc-custom-samples/powershell/event-demo/
  3. Run the following command to deploy the project:
    s deploy -y
    Sample output:
    [2021-09-08T15:58:14.658] [INFO ] [S-CLI] - Start ...
    [2021-09-08T15:58:15.771] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou
    [2021-09-08T15:58:15.772] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-09-08T15:58:15.772] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-09-08T15:58:15.772] [INFO ] [FC-DEPLOY] - Using accessKeySecret: LTAI4G4cwJkK4Rza6xd9****
      Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch.
    [2021-09-08T15:58:16.444] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-08T15:58:16.738] [INFO ] [FC-DEPLOY] - Checking Function powershellEventFunc exists
      Make service custom-demo success.
      Make function custom-demo/powershellEventFunc success.
    [2021-09-08T15:58:17.827] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-08T15:58:17.920] [INFO ] [FC-DEPLOY] - Checking Function powershellEventFunc exists
    Tips for next step
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
      region: cn-hangzhou
        name: custom-demo
        name: powershellEventFunc
        runtime: custom
        handler: index.handler
        memorySize: 512
        timeout: 3
  4. Run the following command to invoke the function:
    s invoke -e "hello"
    Sample output:
    [2021-09-09T16:41:37.765] [INFO ] [S-CLI] - Start ...
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: 8ce302bc-6eba-4607-abea-63b2e801e556
    FC Invoke End RequestId: 8ce302bc-6eba-4607-abea-63b2e801e556
    Duration: 36.61 ms, Billed Duration: 37 ms, Memory Size: 512 MB, Max Memory Used: 110.18 MB
    ========= FC invoke Logs end =========
    FC Invoke Result:
    End of method: invoke