0

I have below code in azure function which is timer triggered. All it does is creates a logs in azure via service principal method and calls Azure APIs to stand up resources.

Functions logs until "logging in". Doesn't go any further and don't log either logging succeed or failed. What I'm missing?

module.exports = function (context, myTimer) {
    var timeStamp = new Date().toISOString();
    context.log("time triggered function entry")

    const ACI   = require('azure-arm-containerinstance');
    const AZ    = require('ms-rest-azure');

    context.log('Starting a container');

    if(process.env.AZURE_CLIENT_ID) {
        var client_id = process.env.AZURE_CLIENT_ID;
    }
    else {
        var client_id = "";
    }

    if(process.env.AZURE_CLIENT_SECRET) {
        var client_secret = process.env.AZURE_CLIENT_SECRET;
    }
    else {
        var client_secret = "";
    }

    if(process.env.TENANT_ID) {
        var tenant_id = process.env.TENANT_ID;
    }
    else {
        var tenant_id = "";
    }

    if(process.env.SUBSCRIPTION_ID) {
        var subscription_id = process.env.SUBSCRIPTION_ID;
    } else {
        var subscription_id = "";
    }

    if(process.env.RESOURCE_GROUP) {
        var resource_group = process.env.RESOURCE_GROUP;
    } else {
        var resource_group = "testAppDeployment";
    }

    if(process.env.CONTAINER_IMAGE_NAME) {
        var containerImageName = process.env.CONTAINER_IMAGE_NAME;
    } else {
        var containerImageName = "<some-containername";
    }

    if(process.env.DEFAULT_REGION) {
        var location = process.env.DEFAULT_REGION;
    } else {
        var location = "eastus"
    }
    var containerGroup = resource_group + "containerGroup";
    var containerName = "tempname";

    context.log("Logging in")
    context.log("tenant id: " + tenant_id)
    context.log("client id: " + client_id)
    context.log("client secret: " + client_secret)

    AZ.loginWithServicePrincipalSecret(
    client_id,
    client_secret,
    tenant_id,
    (err, credentials) = {
        if (err) {
        context.log("logging failed")
        throw err;
    }
    let client = new ACI(credentials, subscription_id);
    context.log("logging succeeded")
    }
}
Rohit Sharma
  • 1,271
  • 5
  • 19
  • 37
explorer
  • 737
  • 1
  • 8
  • 23
  • One thing you are missing is a call to `context.done()` after `logging succeeded` statement. This would signal that function execution is complete. Please check if it helps. – Mikhail Shilkov Jun 25 '18 at 06:38
  • @Mikhail...Thanks for suggestion ...I have it in my full code this is just a snippet of it...I will add it here though – explorer Jun 25 '18 at 15:05

0 Answers0