Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Node 22 functions #2269

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/forty-bulldogs-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@aws-amplify/backend-function': minor
---
sobolk marked this conversation as resolved.
Show resolved Hide resolved

Add support to `@aws-amplify/backend-function` for Node 22

Add support to `@aws-amplify/backend-function` for Node 22, which is a [supported Lambda runtime](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtime-deprecation-levels) that was added in [`aws-cdk-lib/aws-lambda` version `2.168.0`](https://github.com/aws/aws-cdk/releases/tag/v2.168.0) on November 20th, 2024
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend-function/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type FunctionProps = {
export type FunctionSchedule = TimeInterval | CronSchedule;

// @public (undocumented)
export type NodeVersion = 16 | 18 | 20;
export type NodeVersion = 16 | 18 | 20 | 22;

// @public (undocumented)
export type TimeInterval = `every ${number}m` | `every ${number}h` | `every day` | `every week` | `every month` | `every year`;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"uuid": "^9.0.1"
},
"peerDependencies": {
"aws-cdk-lib": "^2.158.0",
"aws-cdk-lib": "^2.168.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update aws-cdk-lib and aws-cdk to matching version in all package.json files across the workspace.

Copy link
Contributor Author

@ataylorme ataylorme Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated package.json files in d443b1f and package-lock.json in 6c98329

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a script update-cdk-in-packages.js to do this. Sharing in case it is useful to you in the future.

/* eslint-disable */
const rootDir = process.cwd();
import fs from 'fs';
import path from 'path';

async function findPackageJsonFiles(dir) {
    let results = [];
    const list = fs.readdirSync(dir);
    for (let file of list) {
        file = path.resolve(dir, file);
        const stat = fs.statSync(file);
        if (stat && stat.isDirectory()) {
            results = results.concat(await findPackageJsonFiles(file));
        } else if (file.endsWith('package.json')) {
            const relativePath = path.relative(rootDir, file);
            if (/packages\/[\w-]+\/package\.json$/.test(relativePath)) {
                results.push(file);
            }
        }
    }
    return results;
}

function updatePackageVersion(packageJson, packageName, newVersion) {
    if (packageJson.dependencies && packageJson.dependencies[packageName]) {
        packageJson.dependencies[packageName] = newVersion;
    }
    if (packageJson.devDependencies && packageJson.devDependencies[packageName]) {
        packageJson.devDependencies[packageName] = newVersion;
    }
    if (packageJson.peerDependencies && packageJson.peerDependencies[packageName]) {
        packageJson.peerDependencies[packageName] = newVersion;
    }
}

async function updateCdkVersion(filePaths) {
    for (let filePath of filePaths) {
        const packageJson = JSON.parse(fs.readFileSync(filePath, 'utf8'));
        updatePackageVersion(packageJson, 'aws-cdk-lib', '^2.168.0');
        updatePackageVersion(packageJson, 'aws-cdk', '^2.168.0');
        fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2) + `\n`, 'utf8');
    }
}

async function main() {
    const packageJsonFiles = await findPackageJsonFiles(path.join(rootDir, 'packages'));
    await updateCdkVersion(packageJsonFiles);
    console.log('Updated package.json files:', packageJsonFiles);
}

main();
/* eslint-enable */

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you.
there will be one more thing needed - additional changeset, since most of packages got touched.
Please see b56d344 for reference. This commit contains a changeset file from last time we upgraded CDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reference, that helps.

"constructs": "^10.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/backend-function/src/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ void describe('AmplifyFunctionFactory', () => {
void it('sets valid runtime', () => {
const lambda = defineFunction({
entry: './test-assets/default-lambda/handler.ts',
runtime: 16,
runtime: 22,
}).getInstance(getInstanceProps);
const template = Template.fromStack(lambda.stack);

template.hasResourceProperties('AWS::Lambda::Function', {
Runtime: Runtime.NODEJS_16_X.name,
Runtime: Runtime.NODEJS_22_X.name,
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/backend-function/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,11 @@ const isWholeNumberBetweenInclusive = (
max: number
) => min <= test && test <= max && test % 1 === 0;

export type NodeVersion = 16 | 18 | 20;
export type NodeVersion = 16 | 18 | 20 | 22;

const nodeVersionMap: Record<NodeVersion, Runtime> = {
16: Runtime.NODEJS_16_X,
18: Runtime.NODEJS_18_X,
20: Runtime.NODEJS_20_X,
22: Runtime.NODEJS_22_X,
};
2 changes: 1 addition & 1 deletion packages/client-config/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export type CustomClientConfig = {
export const DEFAULT_CLIENT_CONFIG_VERSION: ClientConfigVersion;

// @public
export const generateClientConfig: <T extends "1" | "1.1" | "1.2" | "1.3" | "0">(backendIdentifier: DeployedBackendIdentifier, version: T, awsClientProvider?: AWSClientProvider<{
export const generateClientConfig: <T extends "1.2" | "1.3" | "1.1" | "1" | "0">(backendIdentifier: DeployedBackendIdentifier, version: T, awsClientProvider?: AWSClientProvider<{
ataylorme marked this conversation as resolved.
Show resolved Hide resolved
getS3Client: S3Client;
getAmplifyClient: AmplifyClient;
getCloudFormationClient: CloudFormationClient;
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ export const packageJsonSchema: z.ZodObject<{
type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"module">, z.ZodLiteral<"commonjs">]>>;
}, "strip", z.ZodTypeAny, {
name?: string | undefined;
type?: "module" | "commonjs" | undefined;
version?: string | undefined;
type?: "module" | "commonjs" | undefined;
ataylorme marked this conversation as resolved.
Show resolved Hide resolved
}, {
name?: string | undefined;
type?: "module" | "commonjs" | undefined;
version?: string | undefined;
type?: "module" | "commonjs" | undefined;
}>;

// @public
Expand Down
Loading