dockeraws-lambdaarm64

cargo lambda build--arm64 not working on al2023


I'm trying to build Rust for Lambda runtime with Amazon Linux 2023(al2023), so everything is running on Docker as below

# Use cargo-lambda as the build environment
FROM ghcr.io/cargo-lambda/cargo-lambda:latest as builder

# Create app directory
WORKDIR /app

# Copy the Cargo.toml and Cargo.lock files
COPY . .

# Build the release version of your application
RUN cargo lambda build --arm64 --release

# Use the AWS Lambda provided base image for custom runtimes
FROM public.ecr.aws/lambda/provided:al2023

# Copy the compiled binary from the builder stage
COPY --from=builder /app/target/lambda/user/bootstrap ${LAMBDA_RUNTIME_DIR}

# Set the CMD to your handler
CMD ["bootstrap"]

The docker file works fine and I can run it with docker run --rm -it -p 9000:8080 my-rust-lambda but when I call the endpoint, I got qemu-aarch64: Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory

what do I miss?


Solution

  • new Dockerfile

    # Use cargo-lambda as the build environment
    FROM ghcr.io/cargo-lambda/cargo-lambda:latest as builder
    
    # Create app directory
    WORKDIR /app
    
    # Copy the Cargo.toml and Cargo.lock files
    COPY . .
    
    # Build the release version of your application
    RUN cargo lambda build --arm64 --release
    
    # Use the AWS Lambda provided base image for custom runtimes
    FROM public.ecr.aws/lambda/provided:al2023
    
    # Copy the compiled binary from the builder stage
    COPY --from=builder /app/target/lambda/user/bootstrap ${LAMBDA_RUNTIME_DIR}
    
    # Set the CMD to your handler
    CMD ["bootstrap"]