简体   繁体   English

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

[英]Azure Function - Event Hub to AWS RDS Postgres

Where I work, we are trying to use an Azure Function to take a JSON string message from an Event Hub and insert it into Postgres RDS in AWS. 在我工作的地方,我们尝试使用Azure函数从事件中心获取JSON字符串消息并将其插入AWS的Postgres RDS中。 Unfortunately, we have to use Postgres RDS for the time being to persist data but this will likely change to an Azure technology in future. 不幸的是,我们暂时必须使用Postgres RDS来保留数据,但是将来可能会改变为Azure技术。

I am able to get the Function bound to an Event Hub and can successfully receive messages. 我能够将功能绑定到事件中心,并且可以成功接收消息。

run.csx 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 project.json

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

I am using Npgsql to try to connect to Postgres but it can't seem to connect giving the following error in the logs: 我正在使用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

I know this database is available to connect to and I have tried upping the Timeout etc in the connection string but no luck. 我知道该数据库可用于连接,并且我尝试在连接字符串中增加Timeout等,但是没有运气。

Is this actually possible to do? 这实际上可行吗?

Many thanks. 非常感谢。

Most probably it's not a timeout, but a firewall sitting between Azure Web App and AWS Database, which blocks the connection. 很有可能不是超时,而是位于Azure Web App和AWS Database之间的防火墙,它阻止了连接。

Azure does not restrict outbound connections, at least not to port 5432. Azure不限制出站连接,至少不限制到端口5432。

So, I guess that's AWS who has a restriction on IP range configured. 因此,我想这是AWS对配置的IP范围有限制的人。 Try adding your Azure IP range to the white list there. 尝试将您的Azure IP范围添加到那里的白名单。

Azure portal doesn't seem to show the Outbound IP ranges for a Function App, but I'm able to see them in Azure Resource Explorer . Azure门户似乎没有显示Function App的出站IP范围,但是我可以在Azure Resource Explorer中看到它们。 The path to your resource will look like 您的资源路径将如下所示

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

search for a property like 搜索像

"outboundIpAddresses": "104.46.38.91,104.46.38.110,104.46.35.12,23.97.218.73"

UPDATE: The outbound IP address is not shown in the portal for a reason. 更新:出站IP地址由于某种原因未在门户中显示。 They are not guaranteed to be stable, since Function App instances may be in different scale sets. 由于Function App实例可能处于不同的比例尺集中,因此不能保证它们是稳定的。 See this answer . 看到这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM