Skip to main content

Node / Serverless setup

We use node 22 in all places

We use serverless 3 (open source form osls https://github.com/oss-serverless/serverless) in all deployments

We bundle with the serverless-esbuild plugin. This is configured to package things individually to make the deployed packages way smaller.

(Exception to this is gf-app which bundles with serverless-bundle as esbuild seems to break the jsforce module).

As node 18 lambda runtime does not include the AWS SDK v2 by default (it switched to AWS SDK v3), we need to include aws sdk v2 as a lambda layer.

You want some thing like this in your serveress.ts / yaml:

plugins: ['serverless-esbuild',   ....],
provider: {
...
layers: [
'arn:aws:lambda:us-east-1:891197216009:layer:aws-sdk-v2-node18:1'
]
},
package: { <-- top level
individually: true
},
custom: {
esbuild: {
external: ['all-the-cities', 'chrome-aws-lambda'],
exclude: ['pg-native', 'aws-sdk']
},

Note that exclude MUST include 'aws-sdk'.

serverless-esbuild should be first in the list of plugins.

Ensuring max concurrency of a lambda function

If using a SQS trigger it is NOT sufficient to set reservedConcurrency on the function itself. You ALSO need to set maximumConcurrency in the sqs event trigger to a number thats the same or less than reservedConcurrency:

    TransformerDWHReader: {
handler: 'transformer/TransformerDWHReader.handler',
memorySize: 512,
reservedConcurrency: 10,
events: [
{
sqs: {
batchSize: 1,
maximumConcurrency: 2,
arn: '${self:custom.sqsQueues.TransformerDWHReaderQueueArn.${self:provider.stage}}'
}
}
],
environment: {
DWH_CONFIG: dwhConfig
},
vpc: {
securityGroupIds: ['sg-accfce81'],
subnetIds: ['subnet-a64ba7c0']
}
},