You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地调试AWS Python Lambda镜像遇404错误,寻求排查方向

自定义Lambda Python运行时本地调试404问题排查求助

我正在开发支持流式响应的Python自定义AWS Lambda运行时,已编写Dockerfile和lambda_function.py,按文档步骤构建镜像并本地启动,但调用时出现以下问题:

构建与启动命令

构建镜像:

docker build --platform linux/amd64 -t docker-image:test .

安装Runtime Interface Client后,执行容器启动命令:

docker run --platform linux/amd64 -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
    --entrypoint /aws-lambda/aws-lambda-rie \
    docker-image:test \
        /usr/local/bin/python -m awslambdaric lambda_function.handler

错误现象

  • 使用curl调用本地服务返回404, page not found
  • 容器日志仅输出:<date time> [INFO] {rapid} exec '/usr/file/local/python' (cwd=/tmp, handler=lambda_function.handler),日志中Python路径/usr/file/local/python明显有误
  • lambda_function.py中handler内的调试打印语句print("handler triggereed")未执行,说明请求未触发handler
  • aws-lambda-rie为二进制文件无法修改调试,恳请提供排查方向

Dockerfile

FROM public.ecr.aws/lambda/provided:al2-x86_64

# Install SSL Li
WORKDIR /tmp
RUN yum install -y perl-core zlib-devel gzip wget tar make gcc
RUN wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz 
RUN ls 
RUN tar -xvf openssl-1.1.1l.tar.gz 
RUN cd openssl-1.1.1l \
    && ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib \
    && make \
    && make install
ENV PATH="/usr/local/ssl/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/ssl/lib:${LD_LIBRARY_PATH}"

# Update YUM
RUN yum update -y

# Download and extract Python
RUN wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
RUN tar xvf Python-3.11.1.tgz

# Configure and compile Python
RUN cd Python-3.11.1 && \
    ./configure --enable-optimizations --with-openssl=/usr/local/ssl && \
    make altinstall

# Verify Python and SSL module
RUN python3.11 --version
RUN python3.11 -m ssl

# Copy custom runtime bootstrap
COPY bootstrap ${LAMBDA_RUNTIME_DIR}
RUN chmod +x ${LAMBDA_RUNTIME_DIR}/bootstrap

# requirements.txt
COPY requirements.txt ${LAMBDA_TASK_ROOT}/requirements.txt
RUN python3.11 -m pip install -r ${LAMBDA_TASK_ROOT}/requirements.txt -t ${LAMBDA_TASK_ROOT}/ 

# Copy function code
COPY lambda_function.py ${LAMBDA_TASK_ROOT}/lambda_function.py

RUN python3.11 -m pip install requests

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "lambda_function.handler" ]

lambda_function.py

#! /usr/bin/env python

import json, boto3

client = boto3.client("bedrock-runtime")

def handler(event, context):
    print("handler triggereed")
    return { 
        "statusCode":200,
        "body":"Hello World"
    }

内容的提问来源于stack exchange,提问作者tobixoxo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:42:10