Example: Lambda
Demonstrates using testcontainers-floci-go to test a Go Lambda function against a local Floci instance.
The test:
- Starts a Floci container with a dedicated Docker network (required for Lambda)
- Compiles a minimal Go handler (
handler/main.go) for Linux/amd64
- Packages it into a zip with the
bootstrap binary (required by provided.al2023 runtime)
- Creates the Lambda function via
CreateFunction
- Waits for the function to become Active
- Invokes it and verifies the response payload
Run
go test -v -timeout 300s ./examples/lambda/...
Code walkthrough
// Start Floci with dedicated network — required for Lambda container execution
fc, err := floci.NewFlociContainer().
WithDedicatedNetwork().
Start(ctx)
defer fc.Stop(ctx)
// Build the handler for the Lambda runtime
cmd := exec.CommandContext(ctx, "go", "build", "-o", binaryPath, "./handler")
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
// Wire up the AWS SDK Lambda client
cfg, _ := config.LoadDefaultConfig(ctx,
config.WithRegion(fc.GetRegion()),
config.WithBaseEndpoint(fc.GetEndpoint()),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
fc.GetAccessKey(), fc.GetSecretKey(), "",
)),
)
client := lambda.NewFromConfig(cfg)
Note: The handler is compiled for linux/amd64 (GOARCH=amd64, ArchitectureX8664). Go's cross-compilation handles this transparently on any host — no extra tooling needed since CGO_ENABLED=0. If you need arm64 Lambda support, change both GOARCH and the Architectures field to ArchitectureArm64.