awslabs/aws-athena-query-federation
[FEATURE] Remove shaded jar file from the container image
Open
#2,410 opened on Nov 19, 2024
enhancementgood first issue
Repository metrics
- Stars
- (611 stars)
- PR merge metrics
- (PR metrics pending)
Description
Is your feature request related to a problem? If yes, please describe.
Currently, the jar file is not removed from the container image after unpacking the jar. That unnecessarily bloats the resulting image by 30-40MiB.
Describe the solution you'd like
Use a multistage build to unpack the jar file and then only copy the unpacked files to the final image. Also use build arguments to keep version information in one place (and update the release script accordingly). For example, for the Athena connector:
# Use an intermediate build image to unpack the jar
FROM public.ecr.aws/lambda/java:11 AS build
ARG VERSION="2022.47.1"
RUN mkdir /build
WORKDIR /build
# Copy function code and runtime dependencies from Maven layout
COPY target/athena-postgresql-${VERSION}.jar .
# Unpack the jar
RUN jar xf athena-postgresql-${VERSION}.jar && rm -f athena-postgresql-${VERSION}.jar
# Build the runtime image without any unnecessary layers
FROM public.ecr.aws/lambda/java:11
COPY --from=build /build ${LAMBDA_TASK_ROOT}
# Command can be overwritten by providing a different command in the template directly.
# No need to specify here (already defined in athena-postgresql.yaml because has two different handlers)
Describe alternatives you've considered N/A
Additional context N/A