Azure函数Oracle连接

k97glaaz  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(86)

您的Azure Function似乎在本地计算机上正常工作,但在部署到Azure Function时返回500错误。在Azure中,函数连接到本地Oracle数据库。
用Python语言编写的Azure函数代码。
请帮助解决这个问题。
先谢了。

3okqufwl

3okqufwl1#

  • 彼得潘的SO thread answer您需要从托管Oracle DB的本地计算机配置站点到站点VPN到Azure站点,其中该功能与VPN网关集成在同一VNET中。
  • 然后安装ODBC驱动程序或最好是JDBC驱动程序用于Oracle DB连接到您的函数,并在函数代码中使用JDBC连接字符串成功建立连接。
  • RCT回答的另一个选择是通过在Docker镜像中安装Oracle客户端,然后在Docker内的Azure函数中运行它们来将函数Dockerize。
    带有Oracle客户端和Azure函数的Docker文件示例:-
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /app

# Install Azure Functions Core Tools
RUN apt-get update && \
    apt-get install -y apt-transport-https && \
    curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    echo "deb [arch=amd64] https://packages.microsoft.com/debian/10/prod buster main" > /etc/apt/sources.list.d/microsoft-prod.list && \
    apt-get update && \
    apt-get install -y azure-functions-core-tools-3

# Install cx_Oracle and any other Python dependencies your function needs
RUN pip install cx-Oracle

# Copy your Azure Functions code into the container
COPY . /app

# Expose the Azure Functions port (default is 7071)
EXPOSE 7071

# Start the Azure Functions host
CMD ["func", "start", "--python"]

Dockerfile 2:-

# Use an official Azure Functions Python runtime image
FROM mcr.microsoft.com/azure-functions/python:3.0

# Install additional OS-level dependencies if needed
# RUN apt-get update && apt-get install -y <package-name>

# Install Python packages
RUN pip install cx-Oracle

# Set environment variables if necessary
# ENV MY_ENV_VAR=value

# Copy the Azure Functions code into the container
COPY . /home/site/wwwroot

# Expose the Azure Functions port (default is 7071)
EXPOSE 7071

# Start the Azure Functions host
CMD [ "azure-functions-core-tools", "host", "start" ]

# Start the Azure Functions host
CMD [ "func", "start" ]

相关问题