简体   繁体   中英

How can I change localhost IP of azure function code when running it locally?

I am new to azure function.

I want to run my azure function code locally (in an azure virtual machine).

I'm running my code using this line in a linux VM terminal: . env/bin/activate && func host start . env/bin/activate && func host start

It was successful with this output.

Azure Functions Core Tools
Core Tools Version:       4.0.4785 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.10.4.19213
                                                                                                                                                                       


Functions:

        update-info: [GET,POST] http://localhost:7071/update-info

However, I wonder if it is possible to change localhost :7071 to the IP of my virtual machine so that it will be available online. Is it? If yes, how?; if not, how can I run HTTPS request/response program in a VM?

Another question if it is possible is can I change it from http to https? If yes, how?

Edited: - Adding Settings from the config files.

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "http": {
      "routePrefix": ""
    }
  }
}

Btw, I already figured out how to run it using https. I had to add --useHTTPS on the command like this: . env/bin/activate && func host start --useHttps . env/bin/activate && func host start --useHttps I just need to know how to change the localhost to the VM IP address.

  1. Created the Azure Linux VM > Hosted Azure Functions Python Project (Http Trigger Function) on it.
  2. Enabled the Ports HTTP, HTTPS & RDP for checking using the browser by enabling the XRDP & installed the Firefox browser

Glad that enabling the HTTPS flag is resolved by yourself.

I'm able to get the Function App Result with the local host and private IP address in Azure Linux VM:

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM