https://serverless-stack.com/ logo
#help
Title
# help
d

Dan Coates

05/20/2022, 2:07 AM
Hi all, I know similar questions have been asked a couple of times in here but I'm a bit stuck on getting
chrome-aws-lambda
and puppeteer working with local sst start. I've tried various combinations of bundle options including
nodeModules
and
externalModules
and
copyFiles
but nothing seems to work and the
nodeModules
and
copyFiles
settings seem to have no effect on what ends up in the artifact file when running via
sst start
. I've also tested out the example at https://github.com/serverless-stack/serverless-stack/tree/master/examples/layer-chrome-aws-lambda and get the same error of
Cannot find module 'chrome-aws-lambda'
If I remove
chrome-aws-lambda
from the
externalModules
setting then there is a different error
Cannot find module ...<path omitted>/backend/functions/puppeteer/lib/Browser
The readme in the example makes it seem like it should work with
sst start
but it doesn't seem to.
o

outaTiME

05/20/2022, 3:08 AM
Hi @Dan Coates, with version of SST are you using? I have it working locally without problems,
i can share some examples so I want to know what version you are using
one of the important things to make it work locally is to have
puppeteer
as a dev dependency
and
chrome-aws-lambda
and
puppeteer-core
as dependencies
d

Dan Coates

05/20/2022, 3:55 AM
Hi @outaTiME I'm using sst 1.1.2
i can share some examples so I want to know what version you are using
that'd be fantastic if you could, thank you
o

outaTiME

05/20/2022, 4:05 AM
great, this is my (partial) package.json:
Copy code
"dependencies": {
  "@serverless-stack/cli": "1.1.2",
  "@serverless-stack/resources": "1.1.2",
  "aws-cdk-lib": "2.24.0",
  "chrome-aws-lambda": "^10.1.0",
  "puppeteer-core": "^10.1.0",
},
"devDependencies": {
  "puppeteer": "^10.1.0"
}
this is the definition on my stack:
Copy code
socialNotify: {
  function: {
    handler: 'src/subscribers/social-notify.handler',
    bundle: {
      externalModules: ['chrome-aws-lambda'],
    },
    layers: ['arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:25'],
    // ~30s
    timeout: '1 minute',
  },
  cdk: {
    subscription: {
      filterPolicy: {
        event: SubscriptionFilter.stringFilter({
          allowlist: ['social-notify'],
        }),
      },
    },
  },
},
finally, you can check my lambda here: https://github.com/outaTiME/ambito-dolar/blob/master/packages/api/src/subscribers/social-notify.js side note, that’s my app’s productive repository that uses SST 0.69 but the lambda stays intact for SST 1.x, hope it helps 🙏
d

Dan Coates

05/20/2022, 4:35 AM
Thanks @outaTiME I really appreciate you taking the time to put together the example. I suspect the difference is that you are using sst in the same package as your application code. We keep our infra code separate from the application code similar to how the example is set up: https://github.com/serverless-stack/serverless-stack/tree/master/examples/layer-chrome-aws-lambda
m

manitej

05/20/2022, 5:38 AM
d

Dan Coates

05/20/2022, 5:49 AM
Hey @manitej yep, I've followed that step by step and get the exact same errors.
m

manitej

05/20/2022, 5:53 AM
locally not working?
d

Dan Coates

05/20/2022, 5:53 AM
that is correct
f

Frank

05/20/2022, 4:09 PM
@outaTiME thanks for helping out 🙌
@Dan Coates could u give the layer-chrome-aws-lambda example a quick try as in?
Let me know!
d

Dan Coates

05/22/2022, 3:10 AM
Hi Frank, thanks for the message, I have actually already tried that example. I'm curious if it works for anyone else? Unless I'm missing some steps or requirements it seems like it wouldn't work because
chrome-aws-lambda
is marked as an externalModule in the stack config, and even if you remove that, you get the
Cannot find module ...<path omitted>/backend/functions/puppeteer/lib/Browser
error I mentioned above.
t

Tony J

06/03/2022, 2:41 AM
Ah I was having this same exact issue as @Dan Coates
d

Dan Coates

06/03/2022, 2:43 AM
Did you manage to resolve it @Tony J?