question

DanieleMellinoIT-3925 avatar image
0 Votes"
DanieleMellinoIT-3925 asked BrunoLucas-9843 commented

Binding Azure Function to Postgres running in a Docker (local)

Hi, I'm pretty new with Azure functions and bindings.
For my project I need to run an azure function when a new action is made on a postgres database.
The database is running on a docker container as well as my future functions (so I'm not using an azure database).
I though about binding the function with the postgres db. However I understood that this could not be supported from here. Therefore my questions are :

Is it true? Can I bind an azure function with a postgres db on a docker?

Do you know about some helpful references where I can look at ?

Which is the right way to tackle it ?


azure-functionsazure-database-postgresqldotnet-ad
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BrunoLucas-9843 avatar image
0 Votes"
BrunoLucas-9843 answered BrunoLucas-9843 commented

Hi @DanieleMellinoIT-3925 ,

Ideally to get "when something happens in Postgres" you would need a azure function trigger with a Postgres binding. Unfortunately that is not available.
202776-image.png

You can try an azure function time trigger to query postgress every x seconds.
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp#ncrontab-expressions

Problem is getting hold of the connection string. you said it is on a docker image. the next will depend of where the docker is hosted. Is that on Azure VM? On-prem?



image.png (23.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have the postgres docker image hosted on premise, sorry I did not mention that.

0 Votes 0 ·
BrunoLucas-9843 avatar image BrunoLucas-9843 DanieleMellinoIT-3925 ·

On that case it becomes more complicated. You would need something like azure vpn gateway to link your on-prem environment to the cloud. https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-about-vpngateways

You may want to check if your company can provide. Maybe they have that already set or something better, but you need something like that to access on-prem from azure function

I'm not a postgresql specialist. if that would provide some sort of web hook or event that can push the changes to an api, you could create an azure function with http trigger (https://www.postgresql.org/docs/current/sql-createtrigger.html)
(https://stackoverflow.com/questions/46540352/calling-restful-web-services-from-postgresql-procedure-function)

If you manage to get the vpn, create a azure function time trigger like I suggested on my answer. You can set a frequency and query postgresql.

0 Votes 0 ·