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
bootstrapbinary (required byprovided.al2023runtime) - Creates the Lambda function via
CreateFunction - Waits for the function to become Active
- Invokes it and verifies the response payload
go test -v -timeout 300s ./examples/lambda/...// 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 sinceCGO_ENABLED=0. If you needarm64Lambda support, change bothGOARCHand theArchitecturesfield toArchitectureArm64.