我希望使用预定的C#Azure功能管理一些Azure资源.
目前在我已经创建的命令行应用程序中,我一直在使用库"Microsoft.IdentityModel.Clients.ActiveDirectory"进行令牌授权,使用"Microsoft.Azure.Management.Compute"进行客户端调用以进行资源管理.
//... var credential generated my AD authentication and extending Microsoft.Rest.ServiceClientCredentials
using (var client = new ComputeManagementClient(credential)) {
client.SubscriptionId = "[SOME_SUBSCRIPTION_ID]";
client.VirtualMachines.BeginPowerOff("[RESOURCE_GROUP]", "[VM_NAME]");
}
Run Code Online (Sandbox Code Playgroud)
我的管理客户端是否可以与Azure资源交互而无需提供凭据建立的用户凭据或密钥保密?
我以前的经验与AWS有关,而且它确实混淆了我对Azure资源管理的看法.
我看过的旧帖子是:启动和停止Azure虚拟机
和
是否可以从Azure功能停止/启动Azure ARM虚拟机?
-EDIT 1-
我希望基于具有各种权限的已分配角色,在AWS资源客户端中为Lambda提供类似于运行时凭据的内容.我会看看证书.
试图弄清楚如何从 azure 函数中使用 SendGrid。找不到太多文档,但这是我尝试过的:
#r "SendGrid"
using SendGrid.Helpers.Mail;
using System;
public static void Run(string myQueueItem, out Mail message, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
message=new Mail();
}
Run Code Online (Sandbox Code Playgroud)
我已经对主题和正文以及集成输出部分中的 api 密钥进行了硬编码。这是我的function.json:
{
"bindings": [
{
"name": "myQueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "send-email-request",
"connection": "myStorage"
},
{
"type": "sendGrid",
"name": "message",
"apiKey": "SG.xxxxxxxxxxx",
"direction": "out",
"to": "me@gmail.com",
"from": "me@gmail.no",
"subject": "hardcoded",
"text": "test213"
}
],
"disabled": false
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Function ($SendEmailOnQueueTriggered) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.SendEmailOnQueueTriggered'. Microsoft.Azure.WebJobs.Host: …Run Code Online (Sandbox Code Playgroud) 我认为对于Azure函数来说,这将是一个完美的入门测试用例。
我们在Azure(SQL数据库)中有一个SQL存储。
使用C#,VS 2017更新了Azure工作流项目。
我们也有一个Blob存储。每天晚上,我都需要一个过程来访问SQL数据库,根据条件收集一组记录,然后对其进行处理以生成将存储在Blob存储中的文件。
我似乎无法克服完成这些任务中的任何一个的困难。所有的教程似乎都是最基本的类型。
我在VS 2017中创建了一个函数,但第一步只是连接到SQL数据库。
我去添加一个新项目:ADO.NET实体数据模型,它的行为就像它正确创建了模型一样,但是没有数据上下文吗?
因此,我决定尝试下一步-创建Blob,然后仅使用经过硬编码的示例数据。再次...找不到有关如何执行此操作的良好指南。
我在local.setting.json文件中有一个“ AzureWebJobsStorage”设置。
我在下面有一个计时器功能:
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
Run Code Online (Sandbox Code Playgroud)
只是有些人朝着正确的方向指点,我会不断努力奋斗...
乔
如何使用listKeys ARM函数列出azure函数应用程序的键?
我的模板:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [],
"outputs": {
"referenceOutput": {
"type": "object",
"value": "[listkeys(resourceId('Microsoft.Web/sites/functions', 'my-function-app','my-function'),'2016-08-01').key]"
}
}
Run Code Online (Sandbox Code Playgroud)
然后运行:
az group deployment create -g my-rg --template-file ./arm.json --mode incremental
Run Code Online (Sandbox Code Playgroud)
错误:
No route registered for '/api/functions/my-function/listkeys?api-version=2016-08-01'
Run Code Online (Sandbox Code Playgroud) 我有以下功能应用程序
[FunctionName("SendEmail")]
public static async Task Run([ServiceBusTrigger("%EmailSendMessageQueueName%", AccessRights.Listen, Connection = AzureFunctions.Connection)] EmailMessageDetails messageToSend,
[ServiceBus("%EmailUpdateQueueName%", AccessRights.Send, Connection = AzureFunctions.Connection)]IAsyncCollector<EmailMessageUpdate> messageResponse,
//TraceWriter log,
ILogger log,
CancellationToken token)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {messageToSend}");
/* Validate input and initialise Mandrill */
try
{
if (!ValidateMessage(messageToSend, log)) // TODO: finish validation
{
log.LogError("Invalid or Unknown Message Content");
throw new Exception("Invalid message content.");
}
}
catch (Exception ex)
{
log.LogError($"Failed to Validate Message data: {ex.Message} => {ex.ReportAllProperties()}");
throw;
}
DateTime utcTimeToSend;
try …Run Code Online (Sandbox Code Playgroud) 是否可以通过变量或可配置项将databaseName和collectionName参数传递给CosmosDBTrigger?
public static void Run([CosmosDBTrigger(
databaseName: "dbname",
collectionName: "colname",
ConnectionStringSetting = "CosmosDbConnectionString",
LeaseCollectionName = "changefeed-leases")]
IReadOnlyList<Document> changeFeedDocuments,
TraceWriter log)
Run Code Online (Sandbox Code Playgroud)
谢谢,Praveen
我想使用ARM模板部署包含代码的功能应用程序,该模板将作为托管应用程序在Azure市场中发布。
我在文档中看到,您可以在ARM模板中添加sourcecontrols元素,该元素可用于指向例如GitHub存储库。但是,我不想使用存储库,我想将代码上传到Function App。
我也知道您可以使用Azure CLI或Powershell上载代码,但是在市场上发布应用程序时这是不可能的。
有没有办法提供一个包含所有内容的程序包,包括所有代码,并使用Azure市场中的ARM模板将其全部上传到Function App?
azure azure-marketplace azure-resource-manager azure-functions
我有一个Azure函数监视Azure服务总线队列,默认锁定持续时间为30秒.此azure函数根据来自队列的消息中的用户信息发送电子邮件通知.
我注意到重复的电子邮件发出并因此检查了跟踪日志,以找出已为同一用户调用了两次azure函数.日志条目如下:
2018-08-09T 14:38:05 .1249371Z - 执行'AzureFunction'(Reason ='在'servicebusqueue'上检测到新的ServiceBus消息.',Id = 4657012a-94ac-4b22-a628-2e94285aeeb7)
2018-08-09 T14:38:33 .3335833Z - 执行'AzureFunction'(Reason ='在'servicebusqueue'上检测到新的ServiceBus消息.',Id = 3ff8eea3-9b9b-43ae-a797-5acf01c2ae6c)
消息只添加到队列一次,我试图了解什么可以生成另一个.可以因为锁定持续时间吗?
azure azureservicebus azure-servicebus-queues azure-servicebus-topics azure-functions
我有带有服务总线主题触发器的Azure服务总线。我的功能看起来像这样
[FunctionName("SbListener")]
public static async Task Run(
[ServiceBusTrigger("test-topic", "test-sub-1", Connection = "ServiceBus")]string message,
[Inject("Microsoft.EventStore.Functions", true)] IWebNotificationManagerFactory webNotificationManagerFactory,
[Inject("Microsoft.EventStore.Functions", true)] ILogger logger)
{ ... }
Run Code Online (Sandbox Code Playgroud)
我的服务总线的配置位于local.settings.json文件中。
"ConnectionStrings": {
"ServiceBus": "Endpoint=sb://<my-sb>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<my-key>"
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是我也想从配置文件中引用主题名称,而不是在中将它们硬编码ServiceBusTrigger。问题是,如果我更改了订阅名称,那么我将不得不重新部署功能代码(我想不惜一切代价避免这种情况)。
azure azureservicebus azure-servicebus-topics azure-functions