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

[BUG] Error: The input directory "/var/bin" does not exist. at Function.executablePath #331

Closed
LeninBoccardo opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@LeninBoccardo
Copy link

LeninBoccardo commented Jan 22, 2025

Can someone help me? I'm using SAM to deploy a lambda function that uses puppeteer to generate PDF files but, running it locally or deploying it gives me the same error, this one bellow:

Error: The input directory "/var/bin" does not exist. at Function.executablePath (/AppData/Local/Temp/tmpsa2mj74m/node_modules/@sparticuz/chromium/build/index.js:229:19) at Runtime.ByA (/AppData/Local/Temp/tmpsa2mj74m/app.ts:39:44) at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)

First of all this is my current template.yaml:

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
gerador-pdf-lambda

Sample SAM Template for gerador-pdf-lambda

Globals:
Function:
Timeout: 30
MemorySize: 512

Resources:
ChromiumLayer:
Type: AWS::Serverless::LayerVersion
Properties:
Description: Chromium with Node.js integration for AWS Lambda
ContentUri: layers/chromium
CompatibleRuntimes:
- &nodejsRuntime nodejs22.x
instances
CompatibleArchitectures:
- &chromiumArch x86_64
RetentionPolicy: Delete
Metadata:
BuildMethod: *nodejsRuntime
BuildArchitecture: *chromiumArch

GeradorPdfFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: app.lambdaHandler
Runtime: nodejs22.x
Architectures:
- x86_64
Events:
GerarPdf:
Type: Api
Properties:
Path: /gerar-pdf
Method: get
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: "es2020"
Sourcemap: true
EntryPoints:
- app.ts

Outputs:
GeradorPdfApi:
Description: "API Gateway endpoint URL for Prod stage for PDF generation"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/gerar-pdf/"
GeradorPdfFunction:
Description: "Gerador PDF Lambda Function ARN"
Value: !GetAtt GeradorPdfFunction.Arn
GeradorPdfFunctionIamRole:
Description: "Implicit IAM Role created for pdf generation function"
Value: !GetAtt GeradorPdfFunctionRole.Arn

Second this is my lambdaHandler:

`import { ProxyHandler } from 'aws-lambda';
import { PdfGeneratorDTO } from './@types/pdfGenerator';
import { gerarPdf } from './gerador/geradorPdf';
import chromium from '@sparticuz/chromium';
import puppeteer from 'puppeteer-core';

export const lambdaHandler: ProxyHandler = async (event, context, callback) => {
if (!event.body) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'missing body',
}),
};
}

try {
    const payload = JSON.parse(event.body) as PdfGeneratorDTO;

    const browser = await puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath(),
        headless: chromium.headless,
    });

    const page = await browser.newPage();

    const pdfGerado = await gerarPdf(page, payload);

    await browser.close();

    return {
        statusCode: 200,
        body: JSON.stringify({
            pdfGerado,
        }),
    };
} catch (err: any) {
    console.log(err);

    return {
        statusCode: err?.status || 500,
        body: JSON.stringify({
            message: err?.message || 'Unexpected error',
        }),
    };
}

};
`

Third these are my folders has this pattern:

Image

And, these are the package.json files dependencies

`layers/chromium package:

"dependencies": {
"@sparticuz/chromium": "^131.0.1"
}
`

`src package:

"dependencies": {
"@sparticuz/chromium": "^131.0.1",
"dayjs": "^1.11.13",
"esbuild": "^0.14.14",
"puppeteer-core": "^24.0.0",
"qrcode": "^1.5.4"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.92",
"@types/node": "^20.5.7",
"@types/qrcode": "^1.5.5",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.5.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
}
`

Finally

I followed some instructions from this page: https://github.com/Sparticuz/chromium/tree/master/examples/aws-sam

And also tried some help from google, chat gpt, issues from github, etc. None helped me to solve my problem. Can someone exploin what am I doing wrong here and how solve that?

@LeninBoccardo LeninBoccardo added the bug Something isn't working label Jan 22, 2025
@LeninBoccardo LeninBoccardo changed the title [BUG] [BUG] Error: The input directory "/var/bin" does not exist. at Function.executablePath Jan 22, 2025
@Sparticuz
Copy link
Owner

that function does it best to 'find' the chromium.br file that contains chromium. If you get that error it means that it was unable to find the file. Make sure of a few things. 1) That the package is included in external dependencies (#24 (comment)) and 2) You may need to directly specify where the file is. (This would change from user to user)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants