Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error EOF (end of file) when running Rod with AWS Lambda. #1171

Open
IgorBrizack opened this issue Feb 20, 2025 · 1 comment
Open

Error EOF (end of file) when running Rod with AWS Lambda. #1171

IgorBrizack opened this issue Feb 20, 2025 · 1 comment
Labels
question Questions related to rod

Comments

@IgorBrizack
Copy link

IgorBrizack commented Feb 20, 2025

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/aws-lambda-go@v1.47.0/lambda/errors.go",
            "line": 39,
            "label": "lambdaPanicResponse"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/invoke_loop.go",
            "line": 122,
            "label": "callBytesHandlerFunc.func1"
        },
        {
            "path": "runtime/panic.go",
            "line": 785,
            "label": "gopanic"
        },
        {
            "path": "github.com/go-rod/rod@v0.116.2/lib/utils/utils.go",
            "line": 68,
            "label": "init.func2"
        },
        {
            "path": "go/pkg/mod/github.com/go-rod/rod@v0.116.2/must.go",
            "line": 36,
            "label": "(*CoelbaV1Command).scrapeCoelbaToken.New.(*Browser).WithPanic.genE.func7"
        },
        {
            "path": "github.com/go-rod/rod@v0.116.2/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/aws-lambda-go@v1.47.0/lambda/handler.go",
            "line": 355,
            "label": "reflectHandler.func2"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/invoke_loop.go",
            "line": 125,
            "label": "callBytesHandlerFunc"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/invoke_loop.go",
            "line": 75,
            "label": "handleInvoke"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/invoke_loop.go",
            "line": 39,
            "label": "startRuntimeAPILoop"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/entry.go",
            "line": 106,
            "label": "start"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/lambda/entry.go",
            "line": 69,
            "label": "StartWithOptions"
        },
        {
            "path": "github.com/aws/aws-lambda-go@v1.47.0/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"
        }
    ]
}
@IgorBrizack IgorBrizack added the question Questions related to rod label Feb 20, 2025
Copy link

Please fix the format of your markdown:

28 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## My launcher config"]
29 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"]

generated by check-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

1 participant