-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.lambda
More file actions
38 lines (28 loc) · 970 Bytes
/
Dockerfile.lambda
File metadata and controls
38 lines (28 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Multi-stage build for AWS Lambda Go function
# Stage 1: Build the Go application
FROM golang:1.24-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Set working directory
WORKDIR /build
# Copy go mod files from project root
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build argument for Lambda path (default: cmd/glad)
ARG LAMBDA_PATH=cmd/glad
# Build the Lambda function
# CGO_ENABLED=0 for static binary
# -ldflags="-s -w" to reduce binary size
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w" \
-o /build/bootstrap \
./${LAMBDA_PATH}
# Stage 2: Create the Lambda runtime image
FROM public.ecr.aws/lambda/provided:al2023
# Copy the binary from builder
COPY --from=builder /build/bootstrap ${LAMBDA_RUNTIME_DIR}/bootstrap
# Set the CMD to your handler (could also be done as a parameter override outside)
CMD [ "bootstrap" ]