可以使用Python编写Azure函数吗?

时间:2019-04-02 04:58:11

标签: python azure azure-functions azure-cosmosdb

我对在Cosmos DB中使用以Python编写的Azure函数感兴趣。

我看到了最近(2月6日)发布的一个演示,该演示演示了如何为AF启用“实验语言支持”。参考此处的演示(https://www.youtube.com/watch?v=pKGVRKtCp7Y)显示启用此支持选项(截至8周前)允许使用Python编写Azure函数。

我已经按照演示中的步骤进行操作,但是我不认为Python是HTTP触发器当前在我的门户中的选项。我想知道是否已经完全放弃了对Python的支持,或者我缺少一个步骤?

请告知。

enter image description here

2 个答案:

答案 0 :(得分:3)

来自GitHub问题:In-portal editing will be disabled for Python Functions

  

Functions v2上的Python Function Apps,已部署到Linux App Service   计划允许进行门户内文件编辑。此功能将被禁用   从2019年3月开始。

不过,您仍然可以使用VS code extensionAzure Functions Core Tools创建Python函数。

答案 1 :(得分:1)

Azure函数CosmosDB触发Python示例。该功能只需读取和转储通过利用CosmosDB输入绑定在Azure Cosmos DB中添加或更改的文档,即可完成

这是相同输入的绑定

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "triggeredCosmosdb",
      "connectionStringSetting": "yoichikademo1_DOCUMENTDB",
      "databaseName": "mydb",
      "collectionName": "mycontent",
      "leaseCollectionName": "mycontent_leaves",
      "createLeaseCollectionIfNotExists": true,
      "direction": "in"
    },
    {
      "type": "documentDB",
      "name": "inputCosmosdb",
      "databaseName": "mydb",
      "collectionName": "mycontent",
      "connection": "yoichikademo1_DOCUMENTDB",
      "direction": "in"
    }
  ],
  "disabled": false
}

这是python函数的代码

import os
import json

# Read Cosmosdb document given from ENV variable named 'inputCosmosdb' - Name for Input CosmosDB binding
inputCosmosdb = open(os.environ['inputCosmosdb'],'r').read()
print(inputCosmosdb)

# Deserialize inputCosmosdb (string) into JSON objects
docObjects = json.loads(inputCosmosdb)

# Dump documents
print("Document Count={}".format(len(docObjects)))
for doc in docObjects:
    print(doc)

您可以在下面的线程中找到更多详细信息

https://github.com/yokawasa/azure-functions-python-samples/tree/master/v2functions/cosmos-trigger-cosmodb-output-binding

如果您正在寻找V1功能,请遵循以下主题

https://github.com/yokawasa/azure-functions-python-samples/tree/master/v1functions/cosmosdb-trigger-cosmosdb-in-binding

此外,在VS代码中,您可以找到许多用于以您选择的语言创建Azure函数的脚手架模板。我建议您下载用于IDE和函数开发的VS代码。

以下是相同镜头的拍摄示例

https://r-vm.com/python-on-azure-functions

希望有帮助。

相关问题