Replies: 7 comments 2 replies
-
Hello and thank you for your interest in this package! For the time being, I converted this issue into a discussion, as I don't have a clear idea about the fix for this right now (and it's also not breaking the library... too much). This sounds quite similar to an issue we encountered quite a while ago (see #135). Back then, it was caused by the dynamic paths to the JSON files - the Vercel bundler couldn't follow those and therefore dropped those files. I'm assuming something similar is happening here - As to your question about why are those files JSON - well, they are data files, and they are automatically generated. While it's possible to generate In the meantime, would you mind sharing details about your |
Beta Was this translation helpful? Give feedback.
-
+1 on this. I literally ran into this just today while deploying a scraper in AWS Lambda. |
Beta Was this translation helpful? Give feedback.
-
For the time being, I'm using |
Beta Was this translation helpful? Give feedback.
-
I actually just realized that the code is also depending on other more complicated data, like zip files, so nvm on the patching. |
Beta Was this translation helpful? Give feedback.
-
I'm actually going to try to include the files during the build step. |
Beta Was this translation helpful? Give feedback.
-
Yeap, that did it. You can just bundle the data files in your lambda code. I'm using pulumi to deploy, and here's an example of how you'd do it: // Lives in deploy/handler.ts
import { createHandlerAssetArchive } from './utils.ts';
export const handler = new aws.lambda.Function('functionName', {
role: role.arn,
runtime: 'nodejs18.x',
memorySize: 1024,
code: createHandlerAssetArchive('../dist/handler.js', {
extraContent: {
data_files: new pulumi.asset.FileArchive(
'../node_modules/header-generator/data_files'
),
},
}),
timeout: 900,
handler: 'index.handler',
});
// Helper in another file that I always use to deploy lambdas with pulumi
// Lives in deploy/utils.ts
import * as pulumi from '@pulumi/pulumi';
export const createHandlerAssetArchive = (
handlerPath: string,
opts?: {
extraContent?: Record<
string,
pulumi.asset.FileAsset | pulumi.asset.FileArchive
>;
}
): pulumi.asset.AssetArchive => {
return new pulumi.asset.AssetArchive({
'index.js': new pulumi.asset.FileAsset(handlerPath),
...opts?.extraContent,
});
}; |
Beta Was this translation helpful? Give feedback.
-
Hi for anyone encountering this but using Serverless Framework (or CloudFormation) the way I solved this was by creating a Lambda Layer. I added the entire Create a directory for the layer, mine is in {
"name": "fingerprint-injector",
"description": "fingerprint injector",
"dependencies": {
"fingerprint-injector": "2.1.49"
}
} Run Add your layer to your # The rest of your Serverless.yml file
layers:
fingerprintInjector:
path: 'layers/fingerprintInjector/'
functions:
yourLambdaName:
handler: ../index.handler
layers:
- !Ref FingerprintInjectorLambdaLayer Finally mark {
external: [
'fingerprint-injector'
]
} |
Beta Was this translation helpful? Give feedback.
-
Hey, I've been trying to use this package within a lambda that is bundled using esbuild.
Unfortunatley the way the JSON files are included means that they are often not included in final builds when bundled and minified.
Is there a reason these are JSON files? Could they not just be constant values within the javascript and you can optionally override them.
Currently I will need to inject these files manually into build outputs but try to make sure they are only included in bundles that use your package which is pretty janky.
Beta Was this translation helpful? Give feedback.
All reactions