Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Initializing AWS Amplify Environment: "Cannot read properties of undefined (reading 'securityType') #14034

Closed
2 tasks done
albiorixvimal opened this issue Dec 6, 2024 · 10 comments
Labels
pending-triage Issue is pending triage platform-pull Issues related to `amplify pull`

Comments

@albiorixvimal
Copy link

How did you install the Amplify CLI?

npm i -g @aws-amplify/cli

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

v14.15.0

Amplify CLI Version

12.13.1

What operating system are you using?

windows

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

no

Describe the bug

I'm encountering an error while trying to initialize or configure my AWS Amplify environment. I am getting the error in amplify cli build.

What I've Tried:
Verified the contents of the aws-exports.js file:

Questions/Help Needed:
What could be causing the securityType property to be undefined?
Is there a specific step I’m missing during Amplify initialization or configuration?
Should securityType be automatically generated in the aws-exports.js file?

Any assistance or guidance would be greatly appreciated. Thank you!

Expected behavior

Build should run sucessfully

Reproduction steps

  1. I attempted to initialize Amplify using the CLI (amplify init or amplify pull).
  2. Integrated the configuration in my project (aws-exports.js) using Amplify.configure().
  3. Ran the application or backend configuration process, which resulted in the above error.

Project Identifier

No response

Log output

Updated to the latest versions of aws-amplify
The error message is as follows:

2024-12-06T07:01:04.780Z [WARNING]: - Fetching updates to backend environment: amplifydev from the cloud.
2024-12-06T07:01:08.775Z [WARNING]: - Building resource api/generateModels
2024-12-06T07:01:09.964Z [WARNING]: ✔ Successfully pulled backend environment amplifydev from the cloud.
2024-12-06T07:01:11.381Z [INFO]: :white_check_mark:
2024-12-06T07:01:13.020Z [INFO]: �[33mNote: It is recommended to run this command from the root of your app directory�[39m
2024-12-06T07:01:14.046Z [WARNING]: - Initializing your environment: amplifydev
2024-12-06T07:01:17.976Z [WARNING]: - Building resource api/generateModels
2024-12-06T07:01:19.114Z [WARNING]: ✔ Initialized provider successfully.
2024-12-06T07:01:23.023Z [WARNING]: ✖ There was an error initializing your environment.
2024-12-06T07:01:23.028Z [INFO]: :octagonal_sign: Cannot read properties of undefined (reading 'securityType')
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

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.
@albiorixvimal albiorixvimal added the pending-triage Issue is pending triage label Dec 6, 2024
@ykethan
Copy link
Member

ykethan commented Dec 6, 2024

Hey @albiorixvimal, could you try adding --debug to the command and provide us the output? This should provide us some additional information such as stack trace

@ykethan ykethan added pending-response Issue is pending response from the issue author platform-pull Issues related to `amplify pull` labels Dec 6, 2024
@albiorixvimal
Copy link
Author

I have already given output with the debug command. you can see my amplify.yml file. see the attached screenshot.

image

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 9, 2024
@ykethan
Copy link
Member

ykethan commented Dec 9, 2024

@albiorixvimal thank you for the getting back on this. On Amplify console, could you add the AMPLIFY_ENABLE_DEBUG_OUTPUT as true environment variable, this should enable the debug output on the command.
https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html#amplify-console-environment-variables

additionally, could you provide us some information on the project, such as resources created in the project(API with auth modes, auth etc)?
Does this error also occur locally when running push or pull? could you run amplify diagnose --send-report and provide us the project identifier?

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 9, 2024
@albiorixvimal
Copy link
Author

Thanks, @ykethan, for replying. I enabled the Debug output in the environment variable; here is the log I am getting after adding it.

2024-12-10T06:29:43.648Z [INFO]: 🛑 Cannot read properties of undefined (reading 'securityType')

92

2024-12-10T06:29:43.649Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

93

DeploymentFault: Cannot read properties of undefined (reading 'securityType')

94

at Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/push-resources.js:362:11)

95

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

96

Cannot read properties of undefined (reading 'securityType')

97

TypeError: Cannot read properties of undefined (reading 'securityType')

98

at transformGraphQLSchemaV2 (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-category-api/lib/graphql-transformer/transform-graphql-schema-v2.js:115:37)

99

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

100

at async transformGraphQLSchema (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-category-api/lib/graphql-transformer/transform-graphql-schema.js:11:43)

101

at async Object.run (/snapshot/amplify-cli/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/push-resources.js:169:7)

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 10, 2024
@ykethan
Copy link
Member

ykethan commented Dec 10, 2024

Hey @albiorixvimal, thank you for the information. From the trace appear to be coming from the graphQL API transformer and noticed the key is referred from the amplify-meta.json file.

const appSyncApi = appSyncAPIs && appSyncAPIs.length && appSyncAPIs.length > 0 ? appSyncAPIs[0] : undefined;
let hasApiKey = false;
if (appSyncApi) {
// Check for legacy security configuration and multi-auth as well
const { authConfig, securityType } = appSyncApi.output;
if (securityType && securityType === 'API_KEY') {
hasApiKey = true;
} else if (authConfig) {

Is the project using a GraphQL API using v1 transformer version? could you provide us the cli.json under the amplify folder?
In your local project, amplify/backend/amplify-meta.json file in the api -> outputs object do you observe a key with securityType?

additionally, noticed a similar issue here: #1162 (comment)
could you review the comment and let us know if this mitigates the error?

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 10, 2024
@albiorixvimal
Copy link
Author

albiorixvimal commented Dec 11, 2024

@ykethan thanks for the quick response.

Updating the backend-config.json file with the comment you mentioned - #1162 (comment)

"output": {
    "securityType": "AMAZON_COGNITO_USER_POOLS"
}

worked initially, but now I’m encountering a new error: graphql.schema not defined after applying these changes.

Now, I encountered an issue where I

couldn’t find the schema at amplify/backend/api/generateModels/schema.graphql

because there is no folder named generateModels in the api directory. However, after adding this output setting, the generateModels folder is created inside api, and due to that it looking for the schema and it causing issue.

I’m unsure whether this folder is autogenerated or if I need to make manual adjustments. I’m relatively new to Amplify and would appreciate guidance.

Here’s my current backend-config.json file:

"generateModels": {
    "output": {
        "securityType": "AMAZON_COGNITO_USER_POOLS"
    },
    "providerPlugin": "awscloudformation",
    "service": "AppSync"
}


here is cli.json as asked

{
  "features": {
    "graphqltransformer": {
      "addmissingownerfields": true,
      "improvepluralization": false,
      "validatetypenamereservedwords": true,
      "useexperimentalpipelinedtransformer": true,
      "enableiterativegsiupdates": true,
      "secondarykeyasgsi": true,
      "skipoverridemutationinputtypes": true,
      "transformerversion": 2,
      "suppressschemamigrationprompt": true,
      "securityenhancementnotification": false,
      "showfieldauthnotification": false,
      "usesubusernamefordefaultidentityclaim": true,
      "usefieldnameforprimarykeyconnectionfield": false,
      "enableautoindexquerynames": false,
      "respectprimarykeyattributesonconnectionfield": false,
      "shoulddeepmergedirectiveconfigdefaults": false,
      "populateownerfieldforstaticgroupauth": false
    },
    "frontend-ios": {
      "enablexcodeintegration": true
    },
    "auth": {
      "enablecaseinsensitivity": true,
      "useinclusiveterminology": true,
      "breakcirculardependency": true,
      "forcealiasattributes": false,
      "useenabledmfas": true
    },
    "codegen": {
      "useappsyncmodelgenplugin": true,
      "usedocsgeneratorplugin": true,
      "usetypesgeneratorplugin": true,
      "cleangeneratedmodelsdirectory": true,
      "retaincasestyle": true,
      "addtimestampfields": true,
      "handlelistnullabilitytransparently": true,
      "emitauthprovider": true,
      "generateindexrules": true,
      "enabledartnullsafety": true
    },
    "appsync": {
      "generategraphqlpermissions": true
    },
    "latestregionsupport": {
      "pinpoint": 1,
      "translate": 1,
      "transcribe": 1,
      "rekognition": 1,
      "textract": 1,
      "comprehend": 1
    },
    "project": {
      "overrides": true
    }
  },
  "debug": {
    "shareProjectConfig": false
  }
}

Questions:

  1. Is the generateModels field autogenerated? When I tried removing generateModels from the backend-config.json, it resulted in additional errors.
  2. Could this securityType error be caused by changes in the latest version of Amplify?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 11, 2024
@ykethan
Copy link
Member

ykethan commented Dec 11, 2024

Hey @albiorixvimal, is this a new project?
could you provide us some additional information on how the GraphQL API was created and its existing configuration?

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 11, 2024
@albiorixvimal
Copy link
Author

albiorixvimal commented Dec 12, 2024

@ykethan Thank you for you quick response and support. I removed that extra generatedModels and resolve all issue. Now I am able to successfully build the backend app.

Once again thank you so much. you saved my days :)

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 12, 2024
@ykethan
Copy link
Member

ykethan commented Dec 13, 2024

Glad to hear you were able to get this working. Closing the issue, do reach out if you require any assistance.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Issue is pending triage platform-pull Issues related to `amplify pull`
Projects
None yet
Development

No branches or pull requests

2 participants