- Newest
- Most votes
- Most comments
The error message concerning "media type" or "manifest" often occurs because modern Docker versions (especially on Mac/Windows) include metadata called build attestations that AWS Lambda's container registry cannot yet process.
To fix the image compatibility issue, try rebuilding and pushing your image with the --provenance=false flag:
docker buildx build --platform linux/amd64 --provenance=false -t your-account-id.dkr.ecr.your-region.amazonaws.com/my-lambda-adf:latest .
Regarding the R runtime in Lambda:
Since you are using Java to trigger R, ensure that your R script does not attempt to write data to the current directory. In AWS Lambda, only the /tmp directory is writable. If your R script generates temporary files or plots, you must explicitly set the working directory or output path to /tmp within your R code or via ProcessBuilder arguments in Java.
Lastly, double-check that you are using Amazon Linux 2023 (if using Java 21) or sticking to Amazon Linux 2 (for Java 17), as the R package dependencies (yum install) vary slightly between these versions.
Yes, it's definitely possible to run R scripts in AWS Lambda using container images. The error you're encountering suggests an issue with how the Docker image is being built or pushed to ECR, rather than a fundamental limitation.
The main issue with your Dockerfile is the ENTRYPOINT configuration. You're trying to use the Lambda Runtime Interface Emulator (RIE) as the entrypoint, but for actual Lambda deployment, you need to use the AWS Lambda Runtime Interface Client (RIC) for Java.
Here are the key problems and solutions:
1. Use the correct base image approach: For Java Lambda functions with custom dependencies like R, you should either:
- Start from a proper Lambda base image that includes the Java runtime
- Or ensure your custom image properly implements the Lambda Runtime API
2. Fix your ENTRYPOINT: Your current ENTRYPOINT is configured for local testing with RIE, but Lambda expects a different setup. For a Java-based Lambda function, you typically need to:
- Use
javato run your handler class directly - Ensure your JAR includes the AWS Lambda Java runtime dependencies
3. Add required Lambda libraries: Make sure your Maven/Gradle build includes the necessary Lambda dependencies:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.2</version>
</dependency>
4. Correct Docker configuration: Your Dockerfile should look more like this:
FROM amazonlinux:2 # Install R and dependencies RUN yum update -y && \ yum install -y R R-devel gcc-c++ gcc-gfortran zlib-devel bzip2 bzip2-libs bzip2-devel \ xz-libs xz-devel pcre2 pcre2-devel libcurl libcurl-devel java-17-openjdk java-17-openjdk-devel && \ yum clean all # Copy application files COPY target/awsLambdaHandler-1.0-SNAPSHOT.jar ${LAMBDA_TASK_ROOT}/lib/ COPY adf_test.R ${LAMBDA_TASK_ROOT}/ WORKDIR ${LAMBDA_TASK_ROOT} # Set the CMD to your handler CMD ["your.package.name.Handler::handleRequest"]
5. Handler specification:
When creating the Lambda function, specify your handler in the format: your.package.name.Handler::handleRequest
6. Verify image compatibility: Ensure you're building for the correct architecture (x86_64 or arm64) and that your Docker build command includes the proper platform flag if needed:
docker build --platform linux/amd64 -t my-lambda-adf .
The combination of Java and R in Lambda is valid - your Java handler can invoke R scripts using ProcessBuilder or similar mechanisms to execute the R runtime with your script as an argument.
Sources
Building Lambda functions with Java - AWS Lambda
Relevant content
- asked 2 years ago
- asked 3 years ago

Hi Florian, thanks for the quick answer I confirm that my R script doesn't write to the current directory, and Amazon Linux 2 is the correct one for me. I tried your suggestion to replace the build command, followed by this push command: docker push <my-account>.dkr.ecr.<my-region>.amazonaws.com/my-lambda-adf:latest But I still get the same error. It looks there are still issues with my Docker file (first time trying to use one)