0
votes

I am trying to create a deployment slot on Azure using node.js SDK (npm package @azure/arm-appservice)

This is how I call the method:

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
    )
}

And I am getting the following error:

Error: The Resource 'Microsoft.Web/sites/test-app-name/slots/test-new-slot-name' under resource group 'test-resource-group-name' was not found.

Which is a very weird, because it says it can't find the resource I am trying to create.

What am I doing wrong?

Thanks

1

1 Answers

0
votes

If you want to create a deployment slot for your web app, you need to use the createOrUpdateSlot method, note the location need to be the same with the web app.

Sample:

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