npm install lemon-core@^4.1.8 --savenvm install 22
nvm use 22- Update
.nvmrcfile to22
- 18.19.1
+ 22.15.1- Update
config.jsNode.js runtime version of your profile
lemon: {
name: 'lemon-app',
- runtime: 'nodejs18.x',
+ runtime: 'nodejs22.x',
},- Update plugins in serverless.yml
plugins:
- - serverless-offline
+ # - serverless-offline # WARN: fails in Node.js 22.x
- serverless-aws-documentation
- serverless-prune-plugin
- serverless-plugin-log-retentionIf you don’t modify the
pluginssection inserverless.yml, you may encounter the following issues:When running
npm run deployin a Node.js 22, you may encounter the following error:Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.Workaround: Execute the deployment command in Node.js 18 (
nvm use 18), while keeping the Lambda runtime asnodejs22.x.
npm install --save-dev lemon-devkit {
"engines": {
- "node": ">=14",
+ "node": ">=22"
},
"dependencies": {
- "lemon-core": "^3.x",
+ "lemon-core": "^4.x",
},
"devDependencies": {
- "lemon-devkit": "^0.0.3",
+ "lemon-devkit": "^0.0.8",
}
}Replace legacy credentials with asyncCredentials():
import { asyncCredentials } from 'lemon-core';
const credentials = await asyncCredentials(PROFILE);- [express.ts Updates]
export const credentials = async (name?: string) => {
const profile = $engine.environ('PROFILE', NAME) as string;
- return $core.tools.credentials(profile);
+ return $core.tools.asyncCredentials(profile);
};Use awsConfig($engine, region) for v3 clients:
import { SQSClient } from '@aws-sdk/client-sqs';
import $engine, { awsConfig } from 'lemon-core';
const client = new SQSClient(awsConfig($engine, 'ap-northeast-2'));To update the src/cores directory in your project using the latest version from lemon-templates-api, follow these steps:
- In your project: Delete the existing src/cores folder.
- From lemon-templates-api: Copy the entire src/cores directory.
- In your project: Paste the copied src/cores directory into the same path (src/cores).
Starting from lemon-core@4.1.x, batch operations require additional IAM permissions.
iamRoleStatements:
- Effect: Allow
Action:
# Existing permissions
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:Query
- dynamodb:Scan
# NEW: v4.1.x batch operations
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
Resource:
- "arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/${self:custom.tables.main}"
- "arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/${self:custom.tables.main}/index/*"| Method | Description | Required Permission |
|---|---|---|
mreadItem |
Batch read (max 100 items/request) | BatchGetItem |
msaveItem |
Batch save (max 25 items/request) | BatchWriteItem |
mupdateItem |
Batch update (max 25 items/request) | BatchWriteItem |
saveAllUpdates({ useBatch: true }) |
AbstractProxy batch mode | BatchWriteItem |
- Upgrade lemon-core to
^4.1.8 - Upgrade to Node.js 22
- Update
.nvmrc - Update
config.jsruntime - Comment out
serverless-offlineplugin
- Update
- Install lemon-devkit (devDependency)
- Migrate AWS SDK v2 → v3
credentials()→asyncCredentials()- Use
awsConfig($engine, region)
- Update src/cores from lemon-templates-api
- Add DynamoDB IAM Permissions (v4.1.x)
dynamodb:BatchGetItemdynamodb:BatchWriteItem
- Review CI/CD environments
- Ensure Node.js 22 in
serverless.yml,Dockerfile, etc.
- Ensure Node.js 22 in