Azure功能 - AWS RDS Postgres的事件中心

时间:2017-04-27 10:07:57

标签: c# azure azure-functions azureportal

在我工作的地方,我们尝试使用Azure功能从事件中心获取JSON字符串消息,并将其插入AWS中的Postgres RDS。不幸的是,我们暂时不得不使用Postgres RDS来保存数据,但这可能会在未来改为Azure技术。

我能够将函数绑定到事件中心并且可以成功接收消息。

run.csx

#r "System.Data"

using System;
using System.Data;
using Npgsql;

public static void Run(string myEventHubMessage, TraceWriter log)
{
    log.Info($"C# Event Hub trigger function processed a message: 
    {myEventHubMessage}");

    using (NpgsqlConnection connection = new NpgsqlConnection(
    "Host=host;Port=5432;Database=database;Username=username;Password=password;Timeout=300"))
    {
        try
        {
            log.Info("Opening connection to Postgres...");
            connection.Open();
            log.Info("Connection open.");
        }
        catch (Exception ex)
        {
            log.Info($"Failed to open connection to Postgres. EXCEPTION: 
            {ex.Message}");
            throw;
        }  
    }
}

project.json

{
  "frameworks": {
  "net46":{
  "dependencies": {
    "Npgsql": "3.2.2",
   }
  }
 }
}

我正在使用Npgsql尝试连接到Postgres,但它似乎无法连接,在日志中出现以下错误:

2017-04-27T09:58:30.710 Failed to open connection to Postgres. EXCEPTION: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我知道这个数据库可以连接到,我已经尝试在连接字符串中增加Timeout等但没有运气。

这实际上可以吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

很可能不是超时,而是Azure Web App和AWS数据库之间的防火墙,它阻止了连接。

Azure不限制出站连接,至少不限制端口5432。

所以,我猜那个配置了IP范围限制的AWS。尝试将Azure IP范围添加到那里的白名单。

Azure门户似乎没有显示功能应用的出站IP范围,但我能够在Azure Resource Explorer中看到它们。资源的路径如下所示

http://resources.azure.com/subscriptions/{subscriptionid}/resourceGroups/{webappplan}
/providers/Microsoft.Web/sites/{functionapp}

搜索

等属性
"outboundIpAddresses": "104.46.38.91,104.46.38.110,104.46.35.12,23.97.218.73"

更新:出于某种原因,出站IP地址未显示在门户中。它们不能保证稳定,因为Function App实例可能在不同的比例集中。请参阅this answer