Skip to content

feat(cli-internal): add lambda layer support to gen2-migration generate command#14780

Open
adrianjoshua-strutt wants to merge 2 commits intogen2-migrationfrom
feat/lambda-layers-14527
Open

feat(cli-internal): add lambda layer support to gen2-migration generate command#14780
adrianjoshua-strutt wants to merge 2 commits intogen2-migrationfrom
feat/lambda-layers-14527

Conversation

@adrianjoshua-strutt
Copy link
Copy Markdown
Member

Description of changes

The gen2-migration generate command now handles Lambda layers
attached to functions. Previously, layer configurations were silently
dropped during migration — users had to manually recreate them in
Gen2 after running the tool.

The generate command already fetches FunctionConfiguration from the
AWS SDK (which includes Layers), but the field was never read. This
PR reads the layer data from the deployed function config and
generates Gen2's native defineFunction({ layers }) property.

Key design decision: The AWS SDK returns layer ARNs but not the
module names that layers export. Gen2's layers record uses module
names as keys (for bundler externalization). Since the actual module
name isn't available from the API, we extract the layer name from the
ARN and use it as the key. Users may need to update the key to match
their actual import path after migration.

Core logic

FunctionGenerator.resolve() now calls extractLayers() to parse
the config.Layers array into a Record<string, string>. The layer
name is extracted from the ARN (segment 6 in the colon-delimited
format). FunctionRenderer.renderLayers() emits the record as an
AST object literal in the defineFunction() call, following the same
pattern used for environment.

extractLayers() validates ARN structure (minimum 8 segments,
resource type must be layer) and throws on duplicate layer names
with a descriptive error message.

Test fixtures

Updated the project-boards test app to include two Lambda layers
on the quotegenerator function. Updated the LambdaMock to read
Layers from CFN templates and return them in the
GetFunctionCommand response.

Documentation

Updated GEN2_MIGRATION_GUIDE.md to change Lambda layer support
from 🔴 (unsupported) to 🟡 (generate ✔, refactor ✗).

Issue #, if available

Closes #14527

Description of how you validated changes

  • All 12 snapshot tests pass (9 apps + 3 unit), including the
    updated project-boards snapshot with layers in the expected
    defineFunction() output
  • 9 new unit tests for extractLayers() covering: undefined input,
    empty array, missing ARNs, malformed ARNs, non-layer ARNs,
    duplicate layer names, 5-layer maximum, and the happy path
  • TypeScript compilation clean (no new errors)
  • All pre-commit hooks pass (sanitize, prettier, lint, commitlint,
    git-secrets)

Checklist

  • PR description included
  • yarn test passes
  • 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 my contribution is made under the terms of the Apache 2.0 license.

…te command

The gen2-migration generate command now reads Lambda layer
configurations from deployed functions and generates the
corresponding `layers` property in `defineFunction()` calls.

Previously, layers were silently dropped during migration,
requiring users to manually recreate layer configurations
in Gen2. Now layer ARNs are extracted from the AWS SDK
response and mapped into Gen2's native `layers` format
using the layer name from the ARN as the key.

Changes:
- Added `layers` to ResolvedFunction and
  RenderDefineFunctionOptions interfaces
- Added extractLayers() with ARN validation and
  duplicate detection
- Added renderLayers() to emit layers in the
  defineFunction() AST
- Updated LambdaMock to return layer data from CFN
  templates
- Updated project-boards test fixtures with layer
  configurations
- Added 9 unit tests for extractLayers() edge cases

All 28 tests pass (12 snapshot + 16 unit).

Closes #14527
---
Prompt: Implement Lambda layers support in the
gen2-migration generate command. The generate command
should read layer configurations from Gen1 functions
and generate the appropriate Gen2 defineFunction()
layers property.
Update GEN2_MIGRATION_GUIDE.md feature coverage matrix to
reflect that Lambda layers attached to functions are now
handled by the generate step. Changed from 🔴 (unsupported)
to 🟡 (generate ✔, refactor ✗).

Standalone Lambda layer resources (function:LambdaLayer in
amplify-meta.json) remain unsupported.
---
Prompt: Update docs for the Lambda layers feature in
gen2-migration generate command.
@adrianjoshua-strutt adrianjoshua-strutt marked this pull request as ready for review April 14, 2026 16:29
@adrianjoshua-strutt adrianjoshua-strutt requested a review from a team as a code owner April 14, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant