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

ENOENT: no such file or directory, open '/var/data/geo.dat' when running on AWS lambda #159

Open
kbrown-medimap opened this issue Mar 28, 2023 · 7 comments

Comments

@kbrown-medimap
Copy link

Getting the above error when trying to use node-geo-tz in an AWS lambda function.

I've upgraded to the latest version of the library, but the issue still occurs.

Is it possible to get this library to work without having to access the file system?

@monemo12
Copy link

I try to put the library into Lambda Layer, and it is working for me.

@evansiroky
Copy link
Owner

This issue is probably related if not duplicate to #111.

@gciluffo
Copy link

gciluffo commented Mar 15, 2024

Running into a similar issue.

@monemo12 What does your layer look like for getting this to work in a lambda?

Tried doing something like this in cdk

const geoTzLayer = new fn.LayerVersion(this, 'GeoTzLayer', {
      code: fn.Code.fromAsset('node_modules/geo-tz'),
      compatibleRuntimes: [fn.Runtime.NODEJS_18_X],
      description: 'Lambda Layer for geo-tz library',
    });

    const lambda = new fn.Function(this, 'Function', {
       ........
      layers: [geoTzLayer],

@monemo12
Copy link

monemo12 commented Apr 5, 2024

Hi @gciluffo, this is my layer and lambda looks like:

const lambdaLayerConfig: Pick<
  aws_lambda_nodejs.NodejsFunctionProps,
  "layers"
> = {
  layers: [
    new aws_lambda.LayerVersion(this, "SharedPackage", {
      code: aws_lambda.Code.fromAsset(
        path.join(FUNC_PATH, "genericLayer/layer.zip")
      ),
      compatibleRuntimes: [
        aws_lambda.Runtime.NODEJS_14_X,
        aws_lambda.Runtime.NODEJS_16_X,
        aws_lambda.Runtime.NODEJS_18_X,
      ],
    }),
  ],
};

const lambda = new fn.Function(this, 'Function', {
       ........
      memorySize: 325,
      bundling: {
        externalModules: ["geo-tz"],
      },
      ...lambdaLayerConfig,

ps. I also adjusted memorySize to aviod memory problem when layer starts at runtime.

@AlessandroVol23
Copy link

Hi 👋🏽
we faced the same issue and thought to solve it with a layer as well. But once we want to deploy to production we get the error that we can't import some dependencies like geobuf.

Which packages exactly did you bundle in this layer? How did you create the actual dependencies in the layer? This would help a lot. If we try to bundle all of them we'd have a size of 350 MB which we cannot deploy because the limit is 250 MB.

Thank you so much 🙏🏽

@gciluffo
Copy link

@monemo12 Thanks for the response. I ended up using an api to get timezone info. We already have a mapbox api integration so just used that.

@danshev
Copy link

danshev commented Sep 3, 2024

For anyone running into this issue who uses CDK, I noticed that including the "bundling" property in my Lambda definition solved the issue for me:

new NodeJSLambda(scope, props.lambdaFunctionName, {
    handler: 'handler',
    functionName: "ThisWorks",
    bundling: {  // <-- adding this section solved the issue
      sourceMap: true,
      externalModules: ['geo-tz'],
    },
    runtime: Runtime.NODEJS_LATEST,
    entry: getTSCode(props.lambdaFunctionName),
    memorySize: 2048,
    reservedConcurrentExecutions: 5,
    timeout: Duration.seconds(300),
    vpc: props.defaultVpc,
    securityGroups: [props.securityGroups.default],
    vpcSubnets: {
      subnets: props.defaultSubnets,
    },
    layers: [props.layers[LambdaLayer.GeoTz]], // <-- just this was not successful
  })

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

No branches or pull requests

6 participants