HI Everyone I’m new here and migrating my Lambdas ...
# help
j
HI Everyone I’m new here and migrating my Lambdas from Serverless.yml to Serverless-Stack. I’m using V1 constructs but also tried with the 0.x constructs before upgrading and got the same error that I’m struggling to resolve. If I run my code using
yarn start
then I don’t have any issues but if I do a
yarn deploy
I get an
Expected signal to be an instanceof AbortSignal
error. It seems related to
node-fetch
requests (The lambda uses the Airtable NPM to request some data from Airtable). I’m guessing there are some permissions needed perhaps I’ve got no VPC’s and it’s not really clear? Anyone seen this or able to help? My Stack is configured as follows:
Copy code
const api = new sst.Api(this, 'Api', {
      authorizers: {
        feAuthorizer: {
          type: 'jwt',
          jwt: {
            issuer: process.env.ISSUER,
            audience: [process.env.AUDIENCE],
          },
        },
      },
      defaults: {
        authorizer: 'feAuthorizer',
      },
      routes: {
        'GET /': 'src/lambda.handler',
        'POST /new-member': {
          function: {
            handler: 'src/newMember/newMemberHandler.handler',
            environment: {
              FE_CLIENT_ID: process.env.FE_CLIENT_ID,
              FE_SECRET: process.env.FE_SECRET,
              FE_TENANT_ID: process.env.FE_TENANT_ID,
              AIRTABLE_API_KEY: process.env.AIRTABLE_API_KEY,
              AIRTABLE_BASE_ID: process.env.AIRTABLE_BASE_ID,
              MONGO_URI: process.env.MONGO_URI,
            },
          },
        },
      },
    });
I should add this lambda works fine when deployed via serverless.yml so it isn’t the code. I also use
serverless-esbuild
to build the deploy
Okay I think it seems to be related to node-fetch and the packaging. I’m not sure why
serverless-esbuild
works but Serverless-stack’s build doesn’t?
Okay I’ve solved this by declaring the
airtable
npm in the functions
bundle: {.nodeModules }
No idea why your bundled version of esbuild fails to bundle this but this method works
f
Hey @Jon Baker, just to clarify, is this what you did?
Copy code
{
  handler: "src/newMember/newMemberHandler.handler",
  environment: {
    ...
  },
  bundle: {
    nodeModules: ["airtable"],
  },
}
Just digged into this a bit more, SST had
minify
enabled by default. And the
node-fetch
doesn’t play well with
minify
according to this issue https://github.com/node-fetch/node-fetch/issues/784
Alternatively, you can try setting
keepNames
, that might work according to this comment https://github.com/node-fetch/node-fetch/issues/784#issuecomment-1014768204
Copy code
{
  handler: "src/newMember/newMemberHandler.handler",
  environment: {
    ...
  },
  bundle: {
    esbuild: {
      keepNames: true
    }
  }
}
Let me know if that works for you.
j
Hi Frank, thanks for your help, I’ve tried this and it seems to build okay and deploy however I do get a typescript error in my stack file in VSCode, so not sure if it is using a previously compiled version of my stack and not picking up these changes?
Copy code
type '{ esbuild: { keepNames: true; }; }' is not assignable to type 'FunctionBundleProp'.
  Object literal may only specify known properties, and 'esbuild' does not exist in type 'FunctionBundleNodejsProps | FunctionBundlePythonProps'.ts(2322)
@Frank just pinging you in case you didn’t see this? Regarding above, I’m guessing you just need to update a type definition somewhere? It works fine as you suggested, I’ve tested and updated our code and we are now fully migrated from Serverless, but typescript complains in Visual Studio code. Thanks