Cannot Create New Environment: "Cannot read properties of undefined (reading 'Region')" β CLI Bug
How did you install the Amplify CLI?
npm install -g @aws-amplify/cli
If applicable, what version of Node.js are you using?
v20.19.3
Amplify CLI Version
14.0.0
What operating system are you using?
macOS Sequoia 15.5
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made to cloud resources. Only attempted local config edits as part of troubleshooting.
Describe the bug
I am unable to create a new Amplify environment using the CLI. Every attempt to run amplify env add fails with the error: π Cannot read properties of undefined (reading 'Region')
This happens regardless of authentication method (Amplify Studio, AWS profile, or access keys), and after reducing team-provider-info.json to only the master environment with the correct region.
Expected behavior
A new environment should be created and listed by the CLI, allowing safe development and testing.
Reproduction steps
Clone the repo and ensure only the master environment exists in team-provider-info.json. Run amplify env add in the project root. Enter a new environment name (e.g., ai). Select awscloudformation as the provider. Select any authentication method. Observe the error.
Project Identifier
31e6e3d41503af3131abab17046800d7
Log output
# Put your logs below this line
π Cannot read properties of undefined (reading 'Region')
Session Identifiers:
- f5d770da-00bb-42b1-9091-9b83b07a9933
- a22fc270-c2df-4476-b4fe-d786abb2bb06
Additional information
Amplify AppId: d20z0issneg3fj Region: eu-west-1 amplify env list only shows master The Amplify Console does not show a "Create new environment" option for this app. Tried all workarounds in issue #12493 and more. This is blocking all feature development and safe testing for my production SaaS app with paying customers.
Before submitting, please confirm:
- [x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [x] I have removed any sensitive information from my code snippets and submission.
I tried replicating this using your instructions with Amplify CLI version 14.0.0 and Node.js version 20.9.0 and I was able to successfully add an environment.
Could you run amplify env add with --debug and share the output you get?
Thank you for looking into this Leena (@ShadowCat567 ). Hereβs the output from running amplify env add --debug using amplify studio:
............. workwall-clean % amplify env add with --debug [WARNING] @aws-cdk/aws-apigatewayv2-alpha.WebSocketApiKeySelectionExpression is deprecated.
This API will be removed in the next major release. [WARNING] @aws-cdk/aws-apigatewayv2-alpha.WebSocketApiKeySelectionExpression is deprecated.
This API will be removed in the next major release. [WARNING] @aws-cdk/aws-apigatewayv2-alpha.MappingValue is deprecated.
This API will be removed in the next major release. Note: It is recommended to run this command from the root of your app directory Using default provider awscloudformation ? Select the authentication method you want to use: Amplify Studio π Cannot read properties of undefined (reading 'Region')
Resolution: Please report this issue at https://github.com/aws-amplify/amplify-cli/issues and include the project identifier from: 'amplify diagnose --send-report' Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
UnknownFault: Cannot read properties of undefined (reading 'Region')
at genericErrorToAmplifyException (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/amplify-exception-handler.js:129:49)
at handleException (/snapshot/amplify-cli/build/node_modules/@aws-amplify/cli-internal/lib/amplify-exception-handler.js:28:28)
at process.
Cannot read properties of undefined (reading 'Region') TypeError: Cannot read properties of undefined (reading 'Region') at init (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/amplify-service-manager.js:107:80) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/initializer.js:95:9)
Session Identifier: 7acbf8b2-a231-4101-9aaf-9bb13aaa5981 admin@MacBookPro workwall-clean %
Or with access keys:
Additional context:
- Every environment in team-provider-info.json has "Region": "eu-west-1"
- This happens with all authentication methods (Amplify Studio, AWS profile, access keys).
- As you've used, I am using Amplify CLI 14.0.0 and Node.js 20.9.0.
- The error persists across clean clones (workwall-clone is the root of a new clone just for this) and after removing all but the master environment.
- I can't seem to create a new env in the Amploify console, so this seems to be my only option
Let me know if you need any more debug output or config files. Thank you!
hmm that's interesting...would you be ok with sharing what your team-provider-info.json file looks like?
Feel free to block out any information you deem sensitive, I mostly want to see what the structure looks like.
This is what the team-provider-info.json looks like for the app I was testing in:
Hi,
I am adding my investigation here for further reference but it might be incorrect. We'll need the team for further review.
Root Cause Analysis
The error occurs in the init function of amplify-service-manager.ts when it tries to compare regions:
// Line ~77 in amplify-service-manager.ts
teamProviderInfo[env][ProviderName].Region === awsConfigInfo.region
Root Cause: The awsConfigInfo parameter passed to the init function is either:
undefined- Missing the
regionproperty - The
regionproperty isundefined
This happens during the amplify env add workflow when:
initializer.tscallsconfigurationManager.getAwsConfig(context)- The configuration manager fails to properly populate the AWS configuration
- The malformed
awsConfigInfois passed toamplify-service-manager.init() - The code attempts to access
awsConfigInfo.regionwithout null checking
flowchart TD
A["amplify env add"] --> B["initializer.ts:run()"]
B --> C["configurationManager.getAwsConfig()"]
C --> D["awsConfigInfo returned"]
D --> E["amplify-service-manager.init()"]
E --> F["teamProviderInfo comparison"]
F --> G["awsConfigInfo.region access"]
G --> H["TypeError: Cannot read properties of undefined"]
subgraph "Problem Area"
C
D
G
end
style H fill:#ffcccc
style G fill:#ffcccc
Possible Fixes/Solutions
-
Add null safety checks in
amplify-service-manager.ts:if ( env !== envName && awsConfigInfo?.region && teamProviderInfo[env][ProviderName].Region === awsConfigInfo.region && // ... rest of conditions ) -
Fix configuration manager to ensure
awsConfigInfois properly populated with region information -
Add validation in the
initfunction to verifyawsConfigInfostructure before use -
Improve error handling to provide more descriptive error messages when configuration is invalid
π The investigation looks incorrect. The casing on the variable name is mismatched, pointing to the wrong side of the conditional.
That said, the stack trace is helpful in providing some insight. Note that the structure of team-provider-info.json at a high level follows this pattern:
{
[environmentName]: {
[provider]: {
// ... provider details ...
}
},
"categories": {
// ... category details ...
}
}
In the code, the ProviderName constant is "awscloudformation". So, it expects that in team-provider-info.json the [provider] key should always be "awscloudformation". I'm not familiar enough with this to know when this would not be the case. But, by changing the [provider] key from "awscloudformation" to anything else, it's pretty clear that teamProviderInfo[env][ProviderName] would be undefined and would result in an error.
@dickiegog, reiterating @ShadowCat567, I think we either need to see your team-provider-info.json, or you just need to correct the bad entries, per the stack trace β unless there's a valid reason for listing a non-"awscloudformation" key there that I'm not yet familiar with!