Open
Description
Rod Version: v0.116.2
I'm struggling to make it work with AWS lambda, this same image I can start and execute the process on my own compute, but when it is deployed the error bellow shows up.
Main content
launcherConfig := cmd.launcherConfig()
defer launcherConfig.Cleanup()
defer launcherConfig.Kill()
u := launcherConfig.MustLaunch()
log.Print("Browser Config")
browser := rod.New().ControlURL(u).MustConnect()
defer browser.MustClose()
log.Print("Accessing Page")
page, err := stealth.Page(browser) // Point where the code fail in aws lambda
if err != nil {
log.Print(err.Error())
panic(err.Error())
}
page.MustNavigate("https://agenciavirtual.neoenergia.com/#/login")
My launcher config
func (cmd *CoelbaV1Command) launcherConfig() *launcher.Launcher {
if os.Getenv("ENV") == "PROD" {
// Do not change this setup, its used to run in container with aws lambda
browserPath := os.Getenv("ROD_BROWSER_PATH")
u := launcher.New().
Bin(browserPath).
NoSandbox(true).
Headless(true).
Leakless(true)
return u
}
// Use this setup to execute localy
u := launcher.New().
Headless(true)
return u
}
Docker Setup
# Etapa 1: Construção do binário da Lambda
FROM public.ecr.aws/docker/library/golang:1.23-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod tidy
COPY . .
# Compila o executável para AWS Lambda
RUN env GOOS=linux GOARCH=amd64 \
go build -o /main cmd/lambda_handler/main.go
# Etapa 2: Instalação do Chromium e Brotli
FROM public.ecr.aws/lambda/provided:al2023 AS chromium
# Instala Brotli diretamente via DNF (sem compilar do zero)
RUN dnf install -y brotli wget && dnf clean all
# Baixa e descomprime o Chromium
RUN wget --progress=dot:giga https://raw.githubusercontent.com/alixaxel/chrome-aws-lambda/master/bin/chromium.br -O /chromium.br && \
brotli -d /chromium.br && \
chmod +x /chromium
# Etapa 3: Criação da imagem final
FROM public.ecr.aws/lambda/provided:al2023
# Instala dependências mínimas para o Chromium no AL2023
RUN dnf install -y \
libX11 \
libXcomposite \
libXcursor \
libXdamage \
libXrandr \
libXtst \
cairo \
pango \
gtk3 \
alsa-lib \
nss \
libgbm \
fontconfig \
&& dnf clean all
# Copia o Chromium descomprimido
COPY --from=chromium /chromium /opt/chromium
RUN chmod 777 /opt/chromium
# Copia o binário compilado da Lambda
COPY --from=build /main /main
ENTRYPOINT ["/main"]
The Error track by aws
{
"errorMessage": "EOF",
"errorType": "errorString",
"stackTrace": [
{
"path": "github.com/aws/[email protected]/lambda/errors.go",
"line": 39,
"label": "lambdaPanicResponse"
},
{
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go",
"line": 122,
"label": "callBytesHandlerFunc.func1"
},
{
"path": "runtime/panic.go",
"line": 785,
"label": "gopanic"
},
{
"path": "github.com/go-rod/[email protected]/lib/utils/utils.go",
"line": 68,
"label": "init.func2"
},
{
"path": "go/pkg/mod/github.com/go-rod/[email protected]/must.go",
"line": 36,
"label": "(*CoelbaV1Command).scrapeCoelbaToken.New.(*Browser).WithPanic.genE.func7"
},
{
"path": "github.com/go-rod/[email protected]/must.go",
"line": 51,
"label": "(*Browser).MustConnect"
},
{
"path": "/app/internal/core/command/coelbaV1.command.go",
"line": 153,
"label": "(*CoelbaV1Command).scrapeCoelbaToken"
},
{
"path": "/app/internal/core/command/coelbaV1.command.go",
"line": 76,
"label": "(*CoelbaV1Command).Execute"
},
{
"path": "/app/internal/dispatcher/dispatcher.go",
"line": 36,
"label": "(*Dispatcher).Dispatch"
},
{
"path": "lambda_handler/main.go",
"line": 54,
"label": "(*App).HandleRequest"
},
{
"path": "reflect/value.go",
"line": 581,
"label": "Value.call"
},
{
"path": "reflect/value.go",
"line": 365,
"label": "Value.Call"
},
{
"path": "github.com/aws/[email protected]/lambda/handler.go",
"line": 355,
"label": "reflectHandler.func2"
},
{
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go",
"line": 125,
"label": "callBytesHandlerFunc"
},
{
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go",
"line": 75,
"label": "handleInvoke"
},
{
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go",
"line": 39,
"label": "startRuntimeAPILoop"
},
{
"path": "github.com/aws/[email protected]/lambda/entry.go",
"line": 106,
"label": "start"
},
{
"path": "github.com/aws/[email protected]/lambda/entry.go",
"line": 69,
"label": "StartWithOptions"
},
{
"path": "github.com/aws/[email protected]/lambda/entry.go",
"line": 45,
"label": "Start"
},
{
"path": "lambda_handler/main.go",
"line": 96,
"label": "main"
},
{
"path": "runtime/proc.go",
"line": 272,
"label": "main"
},
{
"path": "runtime/asm_amd64.s",
"line": 1700,
"label": "goexit"
}
]
}
Activity