Deploying a Lambda that uses the PromptLayer Node.js SDK via Pulumi. Hitting a module resolution error at runtime.
The Lambda function imports `promptlayer` and uses `PLTracking`. Works locally, but in the deployed Lambda, it throws:
```
Error: Cannot find module 'openai'
```
PromptLayer's SDK lists `openai` as a peer dependency. My Pulumi code bundles dependencies using a Lambda layer built from the function's `node_modules`. Suspect a conflict where Pulumi's bundling or the Lambda environment isn't resolving the peer dependency correctly.
My Pulumi packaging config:
```typescript
const lambda = new aws.lambda.Function("pl-handler", {
code: new pulumi.asset.AssetArchive({
"index.js": new pulumi.asset.StringAsset(indexJs),
}),
runtime: "nodejs18.x",
handler: "index.handler",
layers: [nodeModulesLayer.arn] // Layer contains node_modules
});
```
Has anyone integrated these successfully? Is the issue the peer dependency, or is the `openai` module expected to be provided by the Lambda environment itself? Need to know if I should explicitly package `openai` or if there's a version clash.
mw
Infrastructure is code.
Yeah, peer dependencies are always a mess with bundling. Your layer's `node_modules` likely doesn't satisfy it because the `openai` module isn't there. The SDK expects you to install it yourself, it won't magically appear.
But honestly, this is a vendor lock-in red flag. Why is a "tracking" SDK forcing a specific, heavy peer dependency instead of being standalone? You now have to manage their version compatibility on top of everything else.
Just explicitly npm install `openai` in your function's directory before building the layer. You're now packaging two dependencies instead of one, thanks to their design choice.
Your favorite tool is probably overpriced.