aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.8k stars 819 forks source link

Adding GraphQL API with Cognito User Pool results in hanging error on push #4856

Open jpignata opened 4 years ago

jpignata commented 4 years ago

Describe the bug When I attempt to add an API with Cognito User Pools authentication on a new application, and I push, I receive the following error and the CLI indefinitely hangs:

Template error: instance of Fn::GetAtt references undefined resource authapiaeaa9b10
There was an error pushing the API resource
ValidationError: Template error: instance of Fn::GetAtt references undefined resource authapiaeaa9b10

Amplify CLI Version You can use amplify -v to check the amplify cli version on your system 4.24.4

To Reproduce Steps to reproduce the behavior or terminal output if applicable

$ amplify init
? Enter a name for the project api
? Enter a name for the environment dev
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building android
Please tell us about your project
? Where is your Res directory:  app/src/main/res
Using default provider  awscloudformation

$ amplify add api
? Please select from one of the below mentioned services: GraphQL
? Provide API name: api
? Choose the default authorization type for the API Amazon Cognito User Pool
Using service: Cognito, provided by: awscloudformation

 The current configured provider is Amazon Cognito.

 Do you want to use the default authentication and security configuration? Default configuration
 Warning: you will not be able to edit these selections.
 How do you want users to be able to sign in? Username
 Do you want to configure advanced settings? No, I am done.
Successfully added auth resource
? Do you want to configure advanced settings for the GraphQL API No, I am done.
? Do you have an annotated GraphQL schema? No
? Do you want a guided schema creation? Yes
? What best describes your project: Single object with fields (e.g., “Todo” with ID, name, description)
? Do you want to edit the schema now? No

$ amplify api push
Current Environment: dev

| Category | Resource name | Operation | Provider plugin   |
| -------- | ------------- | --------- | ----------------- |
| Api      | api           | Create    | awscloudformation |
? Are you sure you want to continue? Yes

The following types do not have '@auth' enabled. Consider using @auth with @model
     - Todo
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/directives#auth

GraphQL schema compiled successfully.

Edit your schema at /Users/pignataj/workspace/tmp/api/amplify/backend/api/api/schema.graphql or place .graphql files in a directory at /Users/pignataj/workspace/tmp/api/amplify/backend/api/api/schema
? Do you want to generate code for your newly created GraphQL API No
⠇ Updating resources in the cloud. This may take a few minutes...Error updating cloudformation stack
✖ An error occurred when pushing the resources to the cloud

Template error: instance of Fn::GetAtt references undefined resource authapiaeaa9b10
There was an error pushing the API resource
ValidationError: Template error: instance of Fn::GetAtt references undefined resource authapiaeaa9b10

Expected behavior I would expect the API to be successfully created, along with the necessary Cognito resources.

Screenshots n/a

Desktop (please complete the following information):

Additional context Nada.

ammarkarachi commented 3 years ago

@jpignata , Can you try amplify push auth and then invoking amplify push api? The api depends on Cognito resources to be already provided before it ends up pushing the API resources. If you just run amplify push that should make sure all your resources are provided in sequence determined by 'dependsOn'

jpignata commented 3 years ago

Yep, amplify push worked fine. Perhaps a better error message?

ammarkarachi commented 3 years ago

Yes I agree, if it fails to find a resource it should prompt them to check the status of resource/categories added. I will mark this as an enhancement