Skip to content

feat(gen2-migration): generate code for non-JS Lambda functions - #14972

Open
sharonyajain wants to merge 1 commit into
devfrom
feat/gen2-migration-non-js-functions
Open

feat(gen2-migration): generate code for non-JS Lambda functions#14972
sharonyajain wants to merge 1 commit into
devfrom
feat/gen2-migration-non-js-functions

Conversation

@sharonyajain

Copy link
Copy Markdown
Contributor

Description of changes

Resolves #14535gen2-migration generate now produces Gen2 code for non-JS Lambda functions (Python, Go, Java, .NET, Ruby) instead of throwing or skipping them.

Previously, the generate command only supported Node.js runtimes. PR #14744 added a skip path (via --skip-validations), but left users to hand-code the Gen2 definition. This PR completes the feature by generating the full resource.ts using Gen2's custom functions pattern.

What it generates (example for Python):

import { execSync } from 'node:child_process';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineFunction } from '@aws-amplify/backend';
import { DockerImage, Duration } from 'aws-cdk-lib';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';

const functionDir = path.dirname(fileURLToPath(import.meta.url));

export const myPythonFunc = defineFunction(
  (scope) =>
    new Function(scope, 'myPythonFunc', {
      handler: 'index.handler',
      runtime: Runtime.PYTHON_3_11,
      timeout: Duration.seconds(20),
      memorySize: 256,
      code: Code.fromAsset(functionDir, {
        bundling: {
          image: DockerImage.fromRegistry('dummy'),
          local: {
            tryBundle(outputDir: string) {
              execSync(`python3 -m pip install ...`);
              execSync(`cp -r ...`);
              return true;
            },
          },
        },
      }),
    }),
);

Key changes:

  • FunctionAssessor: All runtimes are now supported for generate (removed the isNonJsRuntime gate)
  • FunctionRenderer: New renderCustomFunction() method emits the CDK Function construct pattern with runtime-specific bundling
  • FunctionGenerator: Removed the throw for non-JS runtimes; branches into custom path when !runtime.startsWith('nodejs')
  • copyFunctionSource: Preserves dependency files (requirements.txt, go.mod, pom.xml) for non-JS functions
  • mapToCdkRuntime(): Maps Lambda runtime strings → CDK Runtime.* enum members

Runtime support:

Lambda Runtime CDK Enum Bundling
python3.x PYTHON_3_X pip install + copy
go1.x / provided.al2023 PROVIDED_AL2023 go build
java* JAVA_* mvn package
dotnet* DOTNET_* dotnet publish
ruby* RUBY_* copy

Issue #, if available

Closes #14535

Description of how you validated changes

  • Runtime mapping unit tests (7 runtimes → correct CDK enum)
  • Custom function rendering tests for Python, Go, Java, .NET
  • Assessor tests updated: all runtimes pass validFor('generate')
  • Manual verification of generated output matches Gen2 docs
  • Pre-existing test for does not render runtime for non-nodejs still passes (Node.js path unchanged)

Checklist

  • PR description included
  • yarn test passes (gen2-migration tests)
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sharonyajain
sharonyajain requested a review from a team as a code owner August 18, 2026 23:51
@sharonyajain sharonyajain self-assigned this Aug 20, 2026
@sharonyajain
sharonyajain changed the base branch from gen2-migration to dev August 21, 2026 13:30
…-migration

Support Python, Go, Java, .NET, and Ruby runtimes in the gen2-migration generate command. Previously non-JS functions threw an UnsupportedRuntimeError; now they produce a resource.ts using Gen2's custom function pattern (defineFunction((scope) => new Function(scope, ...))) with the appropriate CDK Runtime enum, runtime-specific bundling, and source copying that retains non-JS dependency manifests (requirements.txt, go.mod, pom.xml, etc.).

- FunctionAssessor: mark all runtimes as supported for generate

- FunctionRenderer: add renderCustomFunction(), mapToCdkRuntime(), renderBundlingBlock()

- FunctionGenerator: branch non-JS runtimes into the custom function path; runtime-aware copyFunctionSource

- Tests updated/added across assessor, renderer, generator, and orchestrator suites (444 gen2-migration tests pass)

Closes #14535
@sharonyajain
sharonyajain force-pushed the feat/gen2-migration-non-js-functions branch from 9caa448 to 268ade1 Compare August 21, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(gen2-migration) generate command should handle non js lambda functions

1 participant