node-geo-tz icon indicating copy to clipboard operation
node-geo-tz copied to clipboard

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

Open kbrown-medimap opened this issue 1 year ago • 7 comments

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?

kbrown-medimap avatar Mar 28 '23 19:03 kbrown-medimap

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

monemo12 avatar May 30 '23 03:05 monemo12

This issue is probably related if not duplicate to https://github.com/evansiroky/node-geo-tz/issues/111.

evansiroky avatar Jun 13 '23 00:06 evansiroky

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],

gciluffo avatar Mar 15 '24 22:03 gciluffo

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.

monemo12 avatar Apr 05 '24 08:04 monemo12

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 🙏🏽

AlessandroVol23 avatar Apr 29 '24 12:04 AlessandroVol23

@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.

gciluffo avatar Apr 29 '24 14:04 gciluffo