You can migrate ASP.NETCore projects in F# by using the custom runtime of Function Compute and HTTP triggers to the cloud with a few clicks. You can use a browser or an HTTP client tool such as cURL to access a function. You can modify the F# sample code to perform secondary development.

Prerequisites

The following operations are complete:

Procedure

  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/f#/http-demo/
  3. Run the following command to install dependencies:
    make build
    Sample output:
    docker run --rm -it -v $(pwd):/tmp mcr.microsoft.com/dotnet/core/sdk:3.1 bash -c "cd /tmp/FSharpDemo && dotnet publish -r linux-x64 -c Release --self-contained true && cd /tmp/FSharpDemo/bin/Release/netcoreapp3.1/linux-x64/publish && mv FSharpDemo bootstrap && chmod +x bootstrap"
    Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      Determining projects to restore...
      Restored /tmp/FSharpDemo/FSharpDemo.fsproj (in 7.04 sec).
      FSharpDemo -> /tmp/FSharpDemo/bin/Release/netcoreapp3.1/linux-x64/FSharpDemo.dll
      FSharpDemo -> /tmp/FSharpDemo/bin/Release/netcoreapp3.1/linux-x64/publish/
  4. Run the following command to deploy the project:
    s deploy -y
    Sample output:
    [2021-09-09T11:06:13.262] [INFO ] [S-CLI] - Start ...
    [2021-09-09T11:06:14.391] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou
    [2021-09-09T11:06:14.392] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-09-09T11:06:14.392] [INFO ] [FC-DEPLOY] - Using accessKeyID: 1880770869023420****
    [2021-09-09T11:06:14.392] [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-09T11:06:15.127] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T11:06:15.371] [INFO ] [FC-DEPLOY] - Checking Function fsharpHttpFunc exists
    [2021-09-09T11:06:21.944] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
    [2021-09-09T11:06:21.973] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
      Make service custom-demo success.
      Make function custom-demo/fsharpHttpFunc success.
      Make trigger custom-demo/fsharpHttpFunc/http_t success.
    [2021-09-09T11:13:26.237] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T11:13:26.406] [INFO ] [FC-DEPLOY] - Checking Function fsharpHttpFunc exists
    [2021-09-09T11:13:26.505] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
    [2021-09-09T11:13:26.657] [INFO ] [FC-DEPLOY] - Using customDomain: auto: fc will try to generate related custom domain resources automatically
      End of request
      Deployed.
      End of request
    [2021-09-09T11:13:31.351] [INFO ] [FC-DEPLOY] - Generated auto custom domain: fsharphttpfunc.custom-demo.188077086902****.cn-hangzhou.fc.devsapp.net
    [2021-09-09T11:13:31.352] [INFO ] [FC-DEPLOY] - Creating custom domain: fsharphttpfunc.custom-demo.188077086902****.cn-hangzhou.fc.devsapp.net
    [2021-09-09T11:13:31.525] [INFO ] [FC-DOMAIN] - Creating custom domain: fsharphttpfunc.custom-demo.188077086902****.cn-hangzhou.fc.devsapp.net
    
    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
    
    
    
    fc-fsharp_demo-fc_fsharp:
      region: cn-hangzhou
      service:
        name: custom-demo
      function:
        name: fsharpHttpFunc
        runtime: custom
        handler: Program.main
        memorySize: 1024
        timeout: 3
      url:
        system_url: >-
          https://188077086902****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/custom-demo/fsharpHttpFunc/
        custom_domain:
          - domain: >-
              http://fsharphttpfunc.custom-demo.188077086902****.cn-hangzhou.fc.devsapp.net
      triggers:
        - type: http
          name: http_t

Result

After the project is deployed, you can view the temporary domain name generated by Function Compute in the execution output. The temporary domain name can be used to access the newly deployed application. For example, run the following command to access the application:

curl http://fsharphttpfunc.custom-demo.188077086902****.cn-hangzhou.fc.devsapp.net
Note The temporary domain name is used only for demonstration and development purposes. It is valid for a limited period of time. You must use a domain name that has obtained an Internet Content Provider (ICP) filing from Alibaba Cloud for production. For more information, see Bind a custom domain name.