Skip to content

(gen2-migration) generate command creates incorrect env variable declaration for a function that accesses a non pascal cased model name table #14561

@iliapolo

Description

@iliapolo

How did you install the Amplify CLI?

npm install --no-save @aws-amplify/cli-internal-gen2-migration-experimental-alpha

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

0.6.0

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

When a model is named in a non pascal case fashion, i.e:

type randomItem @model {...}

And a function is configured to have access to this model table, the generated (snippet) code is incorrect:

backend.quotegenerator.addEnvironment("API_BACKENDONLY_RANDOMITEMTABLE_NAME", backend.data.resources.tables["Randomitem"].tableName);
backend.data.resources.tables["randomItem"].grant(backend.quotegenerator.resources.lambda, "dynamodb:Put*", "dynamodb:Create*", "dynamodb:BatchWriteItem", "dynamodb:PartiQLInsert", "dynamodb:Get*", "dynamodb:BatchGetItem", "dynamodb:List*", "dynamodb:Describe*", "dynamodb:Scan", "dynamodb:Query", "dynamodb:PartiQLSelect", "dynamodb:Update*", "dynamodb:RestoreTable*", "dynamodb:PartiQLUpdate", "dynamodb:Delete*", "dynamodb:PartiQLDelete");

Notice the value of the env variable is backend.data.resources.tables["Randomitem"].tableName, but our model is named randomitem. Also notice that the next line does actually use the correct casing:

backend.data.resources.tables["randomItem"].grant(...)

Deploying this code results in:

2026-01-28T22:48:01.995Z [INFO]: [BackendBuildError] Unable to deploy due to CDK Assembly Error
                                 ∟ Caused by: [AssemblyError] Assembly builder failed
                                 ∟ Caused by: [TypeError] Cannot read properties of undefined (reading 'tableArn')

Expected behavior

backend.quotegenerator.addEnvironment("API_BACKENDONLY_RANDOMITEMTABLE_NAME", backend.data.resources.tables["randomitem"].tableName);
backend.data.resources.tables["randomItem"].grant(backend.quotegenerator.resources.lambda, "dynamodb:Put*", "dynamodb:Create*", "dynamodb:BatchWriteItem", "dynamodb:PartiQLInsert", "dynamodb:Get*", "dynamodb:BatchGetItem", "dynamodb:List*", "dynamodb:Describe*", "dynamodb:Scan", "dynamodb:Query", "dynamodb:PartiQLSelect", "dynamodb:Update*", "dynamodb:RestoreTable*", "dynamodb:PartiQLUpdate", "dynamodb:Delete*", "dynamodb:PartiQLDelete");

Reproduction steps

  1. Add a non pascal named model name to your GraphQL schema:
type randomItem @model @auth(rules: [
  { allow: public, operations: [read] },
  { allow: owner, operations: [create, read, update, delete] }
]) {
  id: ID!
  name: String!
  description: String
  images: [String]
  projectID: ID
}
  1. Configure a function to have access to this model:
  2. Run gen2-migration generate
  3. Deploy the generated code.

Project Identifier

No response

Log output

Details
# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions