Azure-创建部署槽node.js-ResourceNotFound

时间:2020-05-11 10:19:52

标签: node.js azure azure-web-app-service

我正在尝试使用node.js SDK(npm软件包@azure/arm-appservice)在Azure上创建部署插槽

这就是我所说的方法:

const msRest = require('@azure/ms-rest-nodeauth');
const armWebsite = require('@azure/arm-appservice');

async function createDeploymentSlot(){
    const credentials = await msRest.loginWithServicePrincipalSecret("clientId", "secret", "domain");
    const webManagementClient = armWebsite.WebSiteManagementClient(credentials, "subscriptionId");
    const deployment = {
        location : "westus"
    }

    return webManagementClient.webApps.createDeploymentSlot(
        "test-resource-group-name", 
        "test-app-name", 
        "", //ID of an existing deployment??
        "test-new-slot-name", 
        deployment
    )
}

我收到以下错误:

错误:资源组“ test-resource-group-name”下的资源“ Microsoft.Web / sites / test-app-name / slots / test-new-slot-name”未找到。

这很奇怪,因为它说找不到我要创建的资源。

我在做什么错了?

谢谢

1 个答案:

答案 0 :(得分:0)

如果要为Web应用程序创建部署插槽,则需要使用createOrUpdateSlot方法,注释 location必须与Web相同应用程序。

示例

const msRest = require('@azure/ms-rest-nodeauth');
const armWebsite = require('@azure/arm-appservice');

async function main(){
    const credentials = await msRest.loginWithServicePrincipalSecret("clientId", "secret", "domain");
    const webManagementClient = new armWebsite.WebSiteManagementClient(credentials, "subscriptionId");

    const siteEnvelope = '{"location":"centralus","enabled":true}';
    const obj = JSON.parse(siteEnvelope);

    const a = await webManagementClient.webApps.createOrUpdateSlot(
        "groupname",
        "joywebapp",
        obj,
        "slot2"
    );
    console.log(a)

}
main();

enter image description here