【问题标题】:Azure - add custom domain from webjob with queuetriggerAzure - 使用 queuetrigger 从 webjob 添加自定义域
【发布时间】:2017-08-21 09:02:31
【问题描述】:

我想要一个由队列触发的网络作业。很简单的东西。

然后,当作业触发时,我想提取值并针对 Web 应用创建自定义域。

实现这一目标的最佳方法是什么? powershell webjobs可以由队列触发吗?

【问题讨论】:

  • 您能否在“添加自定义域”方面多解释一下您想要做什么?

标签: powershell azure azure-webjobs


【解决方案1】:

查看这篇文章:

How to use Azure queue storage with the WebJobs SDK

您还可以使用 Azure Function 从队列中触发作业:

Create a function triggered by Azure Queue storage

Azure Function 支持 Powershell:

  • 创建函数应用
  • 创建 PowerShell 函数:

  • 现在您有一个由队列触发的 PowerShell 函数:

【讨论】:

    【解决方案2】:

    我还必须处理相同的场景。我找不到由用 powershell 编写的队列触发的 webjobs 的东西。所以我利用队列触发的Azure函数来设置自定义域并绑定Azure提供的SSL。我可以通过使用 powershell 来实现这一点。在我的情况下,我还必须在处理完队列后进行数据库更新。请确保在“requirements.psd1”文件中添加所需的模块。

    以下是我在队列触发的 azure 函数中使用的 powershell 脚本。确保将环境变量也添加到函数应用配置应用程序设置中(例如,WebAppName)。

    using namespace System.Net
    using namespace System.Management.Automation
    
    param([string] $QueueItem, $TriggerMetadata)
    Write-Host "PowerShell queue trigger function processed work item: $QueueItem"
    Write-Host "Queue item insertion time: $($TriggerMetadata.InsertionTime)"
    
    $cusDomainQueue = $QueueItem.Split("|")
    $fqdn = $cusDomainQueue[0]
    $userId = $cusDomainQueue[1]
    
    if ($fqdn) {
        $webappname = $env:WebAppName 
        $resourcegroup = $env:ResourceGroupName 
        $azureAccountName = $env:AzureAppClientId
        $azurePassword = ConvertTo-SecureString $env:AzureAppClientSecret -AsPlainText -Force
        $azureTenant = $env:TenantId
        try {
            $azureCredentials = New-Object PSCredential($azureAccountName, $azurePassword)
            Write-Host "Initialized Credential"
            
            Disable-AzContextAutosave
    
            $azureProfile = Connect-AzAccount -ServicePrincipal `
                -Credential $azureCredentials `
                -Tenant $azureTenant
            Write-Host "Connected AzureAccount"
    
            $webApp = Get-AzWebApp -Name $webappname
            $hostNames = $webApp.HostNames
            $hostNames = $hostNames + $fqdn
    
            $setDomainName = Set-AzWebApp -Name $webappname `
            -ResourceGroupName $resourcegroup `
            -HostNames @($hostNames) `
            -DefaultProfile $azureProfile
    
            if ($setDomainName.EnabledHostNames -Contains $fqdn)
            {
                Write-Host "Set domain name successful"
    
                $setSSL = New-AzWebAppCertificate -Name $webappname `
                    -ResourceGroupName $resourcegroup `
                    -WebAppName $webappname `
                    -HostName $fqdn `
                    -AddBinding -SslState 'SniEnabled' `
                    -DefaultProfile $azureProfile 
                Write-Host "Set SSL successful" 
                $body = "Custom domain mapped and SSL certificate binding completed."
    
                Write-Host "Updating db"
                Invoke-Sqlcmd -Query "<YourQuery>" -ConnectionString $env:ConnectionString
                Write-Host "Db updated"
            }
            else
            {
                Write-Host "Couldn't add domain $fqdn"
            }
        }
        catch {
            Write-Host "Exception occurred while adding domain $fqdn"
        }    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      相关资源
      最近更新 更多