我在azure
函数中有以下代码,该代码是计时器触发的。它所做的全部工作就是通过服务主体方法在Azure中创建日志,并调用Azure API来维护资源。
功能会一直记录,直到“登录”为止。不要再走了,也不要记录成功或失败的记录。我想念的是什么?
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")
}
}