【问题标题】:Containerized AWS Lambda: python handler cannot access /home/app (but it CAN access /tmp)容器化 AWS Lambda:python 处理程序无法访问 /home/app(但它可以访问 /tmp)
【发布时间】:2021-04-14 14:02:57
【问题描述】:

我正在将 Docker 容器部署到 AWS Lambda,遵循 https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/

我遇到了某种文件权限故障。

如果 Docker 映像部署在 AWS 上,我的 python 处理程序无法访问 /home/app(但它可以访问 /tmp)。

在我的本地机器上,两条路径都可以正常工作。

Dockerfile

ENTRYPOINT [ "/entry.sh" ]
CMD [ "app.handler" ]

entry.sh

#!/bin/sh
echo foo > /home/app/f
exec python -m awslambdaric $1

app.py

def handler(event, context):
    with open('/home/app/f', 'r') as file:
        data = file.read()
    return { "response" : data }

部署到 AWS Lambda,它返回:

{
  "errorMessage": "[Errno 2] No such file or directory: '/home/app/f'",
  "errorType": "FileNotFoundError",
  "stackTrace": [
    "  File \"/home/app/app.py\", line 25, in handler\n    with open('/home/app/f', 'r') as file:\n"
  ]
}

/home/app 更改为/tmp 可以解决此问题。

有什么办法可以解除这个限制?

RUN mkdir -p /home/app
RUN chmod a+rwx /home/app

^ chmod 没有修复它。

PS 我想知道我是否应该将此作为错误提交。向负责容器化 lambdas 的亚马逊工程师报告这个上游的正确方法是什么?

【问题讨论】:

    标签: docker aws-lambda file-permissions


    【解决方案1】:

    传统上,Lambda 始终使用only had the /tmp directory (512mb) 进行 rw 操作。当您在本地主机上运行代码时,您有权使用 /home/app 目录。

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2019-07-18
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多