Amplify: How to remove Auth and add new Auth resource with Api resource. Error Template error: instance of Fn::GetAtt references undefined resource

Viewed 1048

In amplify, I have added Api and a Auth (AWS Cognito) resources as follows. The Api is configured to use Auth Cognito User Pool to authenticate.

    ┌──────────┬───────────────┬───────────┬───────────────────┐
    │ Category │ Resource name │ Operation │ Provider plugin   │
    ├──────────┼───────────────┼───────────┼───────────────────┤
    │ Auth     │ testd50c8ec7  │ No Change │ awscloudformation │
    ├──────────┼───────────────┼───────────┼───────────────────┤
    │ Api      │ testApi       │ No Change │ awscloudformation │
    └──────────┴───────────────┴───────────┴───────────────────┘

I'm still in development and I want to change Auth (Cognito) to login with phone number. So, I have to remove Auth and add a new Auth resource (changing an existing user pool with phone log in is not allowed). When I remove the Auth resource and do a amplify push. I get an error:

Template error: instance of Fn::GetAtt references undefined resource testd50c8ec7

What should I do to remove the old and add a new Auth resource?

1 Answers

I struggled with this for many days so I'm typing this answer up to help myself (and the reader) hours of future frustration.

It seems like once Api is linked to an Auth user pool configuration, it always needs an active Auth Cognito User Pool resource available. So, I needed to follow these steps in order:

  1. Remove the old Auth
amplify remove auth
  1. ADD a new Auth resource
amplify add auth

Feel free to modify ./backend/auth/<new resource name>/parameters.json and backend/auth/<new resource name>/<new resource name>-cloudformation-template.yml to your liking based on this AWS doc

  1. UPDATE the Api resource so it picks up the new Auth name to be created.
% amplify update api

? Please select from one of the below mentioned services: GraphQL
? Select from the options below Update auth settings
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API API key
API key configuration
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 7
  1. Now, amplify status should show something like this:
┌──────────┬─────────────────┬───────────┬───────────────────┐
│ Category │ Resource name   │ Operation │ Provider plugin   │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Auth     │ test852bbeb0    │ Create    │ awscloudformation │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Api      │ testApi         │ Update    │ awscloudformation │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Auth     │ testd50c8ec7    │ Delete    │ awscloudformation │
└──────────┴─────────────────┴───────────┴───────────────────┘
  1. Now you amplify push with no errors or struggle.
Related