前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过Restful API创建Azure Lambda Function - 不太稳定,时而遇到400Bad Request

通过Restful API创建Azure Lambda Function - 不太稳定,时而遇到400Bad Request

作者头像
Jerry Wang
发布2020-04-25 13:25:42
7470
发布2020-04-25 13:25:42
举报

Our team is trying to create functions via Restful API as documented here:

https://docs.microsoft.com/en-us/rest/api/appservice/webapps/createfunction

This API can work, sometimes.

We are testing it using postman with url:

https://management.azure.com/subscriptions//resourceGroups/ep-lambda-functions/providers/Microsoft.Web/sites/beforeCreateUser/functions/strange?api-version=2019-08-01

In HTTP request body, maintain the following JSON source code:

代码语言:javascript
复制
{
 "properties": {
 "files": {
 "index.js": "console.log(\"Hello\");"
},
 "test_data": "{\r\n    \"name\": \"Azure\"\r\n}",
 "config": {
	"bindings": [
	{
		"authLevel": "function",
		"type": "httpTrigger",
		"direction": "in",
		"name": "req",
		"methods": ["get", "post"]
	},
	{
		"type": "http",
		"direction": "out",
		"name": "res"
	}
	],
	"disabled": false
}
}
}

Execute the request in postman, sometimes the API returns 201 Created as expected. Unfortunately sometimes, we get HTTP 400 bad request instead:

Error detail:

代码语言:javascript
复制
{
    "Code": "BadRequest",
    "Message": "Encountered an error (InternalServerError) from host runtime.",
    "Target": null,
    "Details": [
        {
            "Message": "Encountered an error (InternalServerError) from host runtime."
        },
        {
            "Code": "BadRequest"
        },
        {
            "ErrorEntity": {
                "Code": "BadRequest",
                "Message": "Encountered an error (InternalServerError) from host runtime."
            }
        }
    ],
    "Innererror": null
}

We can ensure the correctness of our HTTP request payload.

When I make some deep research, I found a fact which makes me even more surprised.

I setup a jMeter project to fire 10 requests to Azure simultaneously:

For the name of functions to be created, I use prefix “jerryfuncv3_” plus {uuid}, which is a randiom integrate between 1 and 100:

only 2 among these 10 requests are successful:

Let’s check detail of one failed request, take this one for example, function name: jerryfuncv3_70

To my surprise(!!!), although the 8 requests return 400 bad request, still I could see all 10 functions are created in Azure, with status “Enabled” marked.

And for some times, the function creation would fail with 400 Bad request as well, even when I create it manually in Azure portal, as below:

代码语言:javascript
复制
{"properties":{"files":{"index.js":"module.exports = async function (context, req) {\r\n    context.log('JavaScript HTTP trigger function processed a request.');\r\n\r\n    if (req.query.name || (req.body && req.body.name)) {\r\n        context.res = {\r\n            // status: 200, /* Defaults to 200 */\r\n            body: \"Hello \" + (req.query.name || req.body.name)\r\n        };\r\n    }\r\n    else {\r\n        context.res = {\r\n            status: 400,\r\n            body: \"Please pass a name on the query string or in the request body\"\r\n        };\r\n    }\r\n};"},"test_data":"{\r\n    \"name\": \"Azure\"\r\n}","config":{"bindings":[{"authLevel":"anonymous","type":"httpTrigger","direction":"in","name":"req","methods":["get","post"]},{"type":"http","direction":"out","name":"res"}],"disabled":false}}}

400 Bad request would appear sometimes in Azure API console as well.

代码语言:javascript
复制
{
  "Code": "BadRequest",
  "Message": "Encountered an error (InternalServerError) from host runtime.",
  "Target": null,
  "Details": [
    {
      "Message": "Encountered an error (InternalServerError) from host runtime."
    },
    {
      "Code": "BadRequest"
    },
    {
      "ErrorEntity": {
        "Code": "BadRequest",
        "Message": "Encountered an error (InternalServerError) from host runtime."
      }
    }
  ],
  "Innererror": null
}

I searched related github issue and cannot find solution.

This issue below might be related, unfortunately no solution are provided. https://github.com/microsoft/vscode-azurefunctions/issues/1838

In a nutshell, we need the API mentioned in the document below to be STABLE, which means, if the function creation is successfully, we expected 201 created status code. The current behavior is quite confusing indeed!

https://docs.microsoft.com/en-us/rest/api/appservice/webapps/createfunction

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档