Skip to content

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

Merged
sharonyajain merged 1 commit into
devfrom
feat/gen2-migration-non-js-functions
Sep 9, 2026
Merged

sharonyajain merged 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
@sharonyajain
sharonyajain force-pushed the feat/gen2-migration-non-js-functions branch from 9caa448 to 268ade1 Compare August 21, 2026 14:46
@sharonyajain
sharonyajain requested a review from Simone319 August 24, 2026 08:56
@Simone319

Copy link
Copy Markdown
Contributor

CodeBuild Batch FAILED — Attempt 1

Batch: AmplifyCLI-PR-Testing:b5e4dc18-299d-4c87-b244-c74b7608ce7d
Source SHA: 268ade11e067737f26630d185833e3080808183d
Result: 2 of 17 build groups FAILED (15 succeeded)

lint — FAILED

  • 875 ESLint problems (0 errors, 875 warnings) were reported — not the direct blocker, since these are warnings.
  • The actual failure comes from Prettier formatting check (Checking formatting...):
    [warn] packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/amplify/function/function.renderer.test.ts
    [warn] packages/amplify-cli/src/commands/gen2-migration/generate/amplify/function/function.generator.ts
    [warn] packages/amplify-cli/src/commands/gen2-migration/generate/amplify/function/function.renderer.ts
    [warn] Code style issues found in 3 files. Forgot to run Prettier?
    
    → Command exited non-zero: source ./shared-scripts.sh && _lint (exit status 1)
  • Fix: run yarn prettier --write (or equivalent repo lint-fix script) on those 3 files under packages/amplify-cli/src/commands/gen2-migration/generate/amplify/function/.

verify_versions_match — FAILED

@aws-amplify/cli-internal version: 14.6.0-dev.268ade11e067737f26630d185833e3080808183d.0
@aws-amplify/cli version: 14.5.2-dev.268ade11e067737f26630d185833e3080808183d.0
  • The dev-version bump for @aws-amplify/cli-internal (14.6.0) and @aws-amplify/cli (14.5.2) are out of sync — they must match.
  • Tool's own guidance from the log:

    Manual fix: add a proper conventional commit that touches the amplify-cli-npm package to correct its version bump. Example: 15dcd96


Reported automatically from the CodeBuild batch run above. Commit status AWS CodeBuild BuildBatch us-east-1 (AmplifyCLI-PR-Testing) has been set to failure.

@sharonyajain
sharonyajain force-pushed the feat/gen2-migration-non-js-functions branch from 268ade1 to 911df30 Compare August 24, 2026 13:05

@Simone319 Simone319 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this — the runtime-mapping coverage and the dependency-manifest preservation are nice touches. One overall question before this is mergeable: has the generated output been deployed and invoked end-to-end for at least one non-JS runtime (e.g. run gen2-migration generate on a Python or Go function, then npx ampx sandbox and a live invoke)? The validation listed is at the transformer/schema level, and several of the inline points below (the Go bootstrap handler, the dropped env vars/permissions, the dummy bundling image) would only surface at deploy/runtime — a single real deploy would confirm the generated function actually stands up.

@sharonyajain
sharonyajain force-pushed the feat/gen2-migration-non-js-functions branch 2 times, most recently from 13155e8 to d35e8cf Compare August 25, 2026 19:41
@sharonyajain

Copy link
Copy Markdown
Contributor Author

On the end-to-end verification question: no — the generated output has not yet been deployed and invoked live for a non-JS runtime. Verification so far is unit/renderer-level (46 function-suite tests, 450 gen2-migration tests, prettier + version-match green). A real gen2-migration generatenpx ampx sandbox → live invoke on a Python/Go function needs an AWS account and a non-JS Gen1 app, which I haven't run.

Flagging this as the open manual-verification item. The inline fixes just pushed (env vars, forced Go bootstrap handler, real bundling image, loud warning for unknown runtimes) are exactly the things a live deploy would most likely have surfaced, so they narrow the risk — but a maintainer live pass (or a sandbox account to use) is still the right gate before merge. Head is now d35e8cfe0a.

…-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 d35e8cf to 2845b27 Compare August 26, 2026 14:36
@sharonyajain
sharonyajain requested a review from Simone319 August 26, 2026 14:42
@sharonyajain
sharonyajain merged commit 3661df1 into dev Sep 9, 2026
6 checks passed
@sharonyajain
sharonyajain deleted the feat/gen2-migration-non-js-functions branch September 9, 2026 13:27
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

2 participants