amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Service: AWSCognitoIdentityProviderService - InvalidParameterException (7.3.3)

Open prabha-912 opened this issue 5 years ago • 24 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

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

v12.16.1

Amplify CLI Version

7.3.3

What operating system are you using?

Ubuntu

Amplify Categories

auth, storage, function, api

Amplify Commands

push, update

Describe the bug

Hi folks,

We are having the issue in congito pool update while doing amplify push. Our dev group didn't made any changes on backend. We're having build settings with the latest version of amplify CLI. While doing backend deployment (amplify push), getting error.

Expected behavior

With the latest version of CLI (7.3.3) we have to deploy our existing stack without fail.

Reproduction steps

  1. Update CLI to 7.3.3
  2. auth with amplify application.
  3. Use amplify push

GraphQL schema(s)

# Put schemas below this line


Log output

Invalid AttributeDataType input, consider using the provided AttributeDataType enum. (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException


Additional information

Once we downgraded to version 7.3.2, its solved.

Note: error is occuring while moving to 7.3.3.

prabha-912 avatar Nov 17 '21 13:11 prabha-912

Hi @prabha-912

  1. Could you please provide us with the entire error log/stack-trace from your amplify push operation.
  2. Can you please provide the contents of  amplify/backend/auth and amplify/backend/storage directory? The above information will help us root cause the problem.

sachscode avatar Nov 17 '21 15:11 sachscode

Hello,

I think I might be running into a similar issue. I am unable to build a new version of my app using the Amplify console. You can find the log attached, as well as my amplify backend config files.

What's strange, this happens only in a particular branch. In different branches, everything works just fine, and Amplify console builds with no problems. The auth and storage configuration is the same for all three branches and we haven't made any changes in several months.

Our Amplify console is configured to use the latest Amplify version. There is a difference between malfunctioning branch and the one that works - the last successful build in the broken one was performed with Amplify CLI 7.3.1. Subsequent builds using 7.4.0 end with an error.

For the one that is working, the latest builds are using 6.4.0 and then 7.4.0, so it appears that 7.3.1 somehow "damaged" the User Pool in the malfunctioning branch.

Also, the last build using 7.3.1 seems to cause problems accessing the S3 buckets - file uploads are not working for Cognito users, and we also encountered problems with reading files using I-Am from our Lambdas.

Is there any way to fix this?

log.txt amplify-auth-storage.zip

oookoook avatar Nov 18 '21 16:11 oookoook

I've tried to change the _LIVE_UPDATES env var in Amplify console to test different CLI versions. I am able to build the app using 7.3.1 and 7.3.2. Anything above does not work and I can't use older versions such as 6.4.0:

2021-11-18T17:20:17.063Z [INFO]: Backend environment production found in Amplify Console app: dreamroi-recommender
2021-11-18T17:20:28.083Z [INFO]: Failed to pull the backend.
2021-11-18T17:20:28.086Z [INFO]: Invalid feature flag configuration
2021-11-18T17:20:28.087Z [INFO]: These feature flags are defined in the "amplify/cli.json" configuration file and are unknown to the currently running Amplify CLI:
                                   - project
                                 This issue likely happens when the project has been pushed with a newer version of Amplify CLI, try updating to a newer version.
                                 Ensure that the CI/CD pipeline is not using an older or pinned down version of Amplify CLI.
                                 Learn more about feature flags: https://docs.amplify.aws/cli/reference/feature-flags

Seems to me that CLI 7.3.1 made some changes to the User Pool that prevents Cloud Formation to update the stack when using newer versions of the CLI, but I am unable to figure out what has changed between the versions.

There are some parameters that are different or contained only in one of the branches: defaultPasswordPolicy - present only in the working stack breakCircularDependency - present only in the failed stack permissions - empty, but present only in the working stack maybe more...

oookoook avatar Nov 18 '21 19:11 oookoook

@oookoook

  1. The amplify folder you attached, Is this the amplify folder of the non-working branch ? Which operation fails for you?
  2. "Invalid feature flag" is generally seen when the amplify folder is generated by a new version of the cli and the older verison of the cli is used to view/mutate the state.

sachscode avatar Nov 18 '21 19:11 sachscode

@sachscode yest, that's the not worikng branch... and also the working one. they are the same.

The only difference is that the not working one was pushed with 7.3.1 previously.

The failing operation is push.

oookoook avatar Nov 18 '21 19:11 oookoook

@oookoook

  1. Do you have any changes before you do a push. ( amplify status -v can be used to view the difference in cloudformation resources)
  2. By push do you mean "amplify push" from the CLI or its through the console. ( I am trying to repro this )

sachscode avatar Nov 18 '21 19:11 sachscode

@sachscode Thank you for having a look at this!

The failing build happens in Amplify Console. The first failed build was initiated by git push to the repo. The changes where only in code of one of the lambda functions, no changes in Amplify resources.

Then I did several re-deploys of different commits in Amplify Console with different versions of the Amplify CLI - but again, the commits differed only in code of Lambdas, not in definitions of AWS resources.

I use only Amplify Console to modify the environment of the branch. I'll try to configure amplify to target that environment and then run amplify status -v and I'll let you know.

oookoook avatar Nov 18 '21 19:11 oookoook

@sachscode Well, it seems I can't do that... Or I don't know how. The thing is, if I do amplify pull of that environment from backend, amplify status -v does not detect any changes - which makes sense, ale it's freshly pulled and I made no changes. And I can't get that information directly from the Amplify Console. :(

But I am 100% sure I made no changes to the auth or storage resources - last changes of these resources tracked in Git (which is all that Amplify Console has available) are several months old...

I noticed that in my auth configuration, I have cloudformation YML template, but when I did the amplify pull of the broken branch, I got the cli-input.json file instead of the CF template, and the CF template is JSON in untracked build folder.

oookoook avatar Nov 18 '21 21:11 oookoook

@oookoook One thing you can do right now to unblock yourself

  1. Install latest version of the Amplify CLI
  2. pull in the latest environment configuration doing amplify pull
  3. in the amplify/backend/auth folder - delete the build/ and cli-inputs.json files and replace it with the files mentioned in here (the YML ones) - https://github.com/aws-amplify/amplify-cli/issues/8917#issuecomment-973058775
  4. amplify push --force
  5. Pin Amplify Console build setting to latest and run your CI build again.

kaustavghosh06 avatar Nov 18 '21 21:11 kaustavghosh06

@kaustavghosh06 Thank you for the advice. I followed the procedure, but the result is the same in step 4:

UPDATE_FAILED      UserPool AWS::Cognito::UserPool Thu Nov 18 2021 23:20:41 GMT+0100 (Středoevropský standardní čas) Invalid AttributeDataType input, consider using the provided AttributeDataType enum. (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID: bf2b6b25-05c3-4c33-8665-c0d245a167af; Proxy: null)

Is it possible that the CF is unable to update the UserPool because the YML template violates some constraints required for the UserPool resource update by CF? For example, I found this issue: https://github.com/aws/aws-cdk/issues/7058 mentioning the same error message with the explanation:

The Cognito service limits that required attributes for a UserPool cannot be modified after it has been created. It turns out this is the error message they throw when this is performed.

I really really don't want to recreate the user pool though... :(

The strange thing is that build with 7.4.0 succeeds when the previous build was with 6.4.0. So it seems that 7.3.1 did something. But I can't figure out what was that change and why it is irreversible - because the YML template was the original one! If anything, I'd expect the build with 7.3.1 to fail if it performed any changes that cannot be done to existing user pool.

oookoook avatar Nov 18 '21 22:11 oookoook

@sachscode Using the @kaustavghosh06, I was able to get the comparison of the stacks:

User pool update analysis

IAM Statement Changes
┌───┬─────────────────┬────────┬────────────────────────────────────┬───────────────────────────┬───────────┐
│   │ Resource        │ Effect │ Action                             │ Principal                 │ Condition │
├───┼─────────────────┼────────┼────────────────────────────────────┼───────────────────────────┼───────────┤
│ - │ ${UserPool.Arn} │ Allow  │ cognito-idp:DescribeUserPoolClient │ AWS:${UserPoolClientRole} │           │
├───┼─────────────────┼────────┼────────────────────────────────────┼───────────────────────────┼───────────┤
│ + │ ${U.s}          │ Allow  │ cognito-idp:DescribeUserPoolClient │ AWS:${UserPoolClientRole} │           │
└───┴─────────────────┴────────┴────────────────────────────────────┴───────────────────────────┴───────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Parameters
[-] Parameter breakCircularDependency: {"Type":"String"}
[-] Parameter useEnabledMfas: {"Type":"String"}
[+] Parameter defaultPasswordPolicy: {"Type":"String"}
[+] Parameter parentStack: {"Type":"String"}
[+] Parameter permissions: {"Type":"CommaDelimitedList"}
[~] Parameter userpoolClientRefreshTokenValidity: {"Type":"String"} to {"Type":"Number"}
[~] Parameter passwordPolicyMinLength: {"Type":"String"} to {"Type":"Number"}

Conditions
[-] Condition ShouldOutputAppClientSecrets: {"Fn::Equals":[{"Ref":"userpoolClientGenerateSecret"},true]}

Resources
[~] AWS::IAM::Role SNSRole replace
 └─ [~] RoleName (requires replacement)
     └─ [~] .Fn::If:
         └─ @@ -5,10 +5,11 @@
            [ ] "Fn::Join": [
            [ ]   "",
            [ ]   [
            [-]     "sns17d7d821",
            [+]     "sns",
            [+]     "17d7d821",
            [ ]     {
            [ ]       "Fn::Select": [
            [-]         3,
            [+]         "3",
            [ ]         {
            [ ]           "Fn::Split": [
            [ ]             "-",
[~] AWS::Cognito::UserPool UserPool 
 ├─ [~] AutoVerifiedAttributes
 │   └─ @@ -1,3 +1,3 @@
 │      [-] [
 │      [-]   "email"
 │      [-] ]
 │      [+] {
 │      [+]   "Ref": "autoVerifiedAttributes"
 │      [+] }
 ├─ [~] Schema
 │   └─ @@ -1,7 +1,12 @@
 │      [ ] [
 │      [ ]   {
 │      [-]     "Mutable": true,
 │      [+]     "Name": "email",
 │      [+]     "Required": "true",
 │      [+]     "Mutable": "true"
 │      [+]   },
 │      [+]   {
 │      [ ]     "Name": "phone_number",
 │      [-]     "Required": true
 │      [+]     "Required": "true",
 │      [+]     "Mutable": "true"
 │      [ ]   }
 │      [ ] ]
 ├─ [-] SmsAuthenticationMessage
 │   └─ {"Ref":"smsAuthenticationMessage"}
 ├─ [~] SmsConfiguration
 │   └─ [~] .SnsCallerArn:
 │       └─ [~] .Fn::GetAtt:
 │           └─ @@ -1,4 +1,1 @@
 │              [-] [
 │              [-]   "SNSRole",
 │              [-]   "Arn"
 │              [-] ]
 │              [+] "SNSRole.Arn"
 ├─ [-] DependsOn
 │   └─ ["SNSRole"]
 └─ [+] UpdateReplacePolicy
     └─ Retain
[~] AWS::Cognito::UserPoolClient UserPoolClientWeb 
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPool"
        [-] ]
        [+] "UserPool"
[~] AWS::Cognito::UserPoolClient UserPoolClient 
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPool"
        [-] ]
        [+] "UserPool"
[~] AWS::IAM::Role UserPoolClientRole replace
 ├─ [~] AssumeRolePolicyDocument
 │   └─ [~] .Statement:
 │       └─ @@ -2,8 +2,12 @@
 │          [ ]   {
 │          [ ]     "Effect": "Allow",
 │          [ ]     "Principal": {
 │          [-]       "Service": "lambda.amazonaws.com"
 │          [+]       "Service": [
 │          [+]         "lambda.amazonaws.com"
 │          [+]       ]
 │          [ ]     },
 │          [-]     "Action": "sts:AssumeRole"
 │          [+]     "Action": [
 │          [+]       "sts:AssumeRole"
 │          [+]     ]
 │          [ ]   }
 │          [ ] ]
 ├─ [~] RoleName (requires replacement)
 │   └─ [~] .Fn::If:
 │       └─ @@ -7,10 +7,11 @@
 │          [ ] "Fn::Join": [
 │          [ ]   "",
 │          [ ]   [
 │          [-]     "upClientLambdaRole17d7d821",
 │          [+]     "upClientLambdaRole",
 │          [+]     "17d7d821",
 │          [ ]     {
 │          [ ]       "Fn::Select": [
 │          [-]         3,
 │          [+]         "3",
 │          [ ]         {
 │          [ ]           "Fn::Split": [
 │          [ ]             "-",
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPoolClient"
        [-] ]
        [+] "UserPoolClient"
[~] AWS::Lambda::Function UserPoolClientLambda 
 ├─ [~] Code
 │   └─ [~] .ZipFile:
 │       └─ @@ -1,1 +1,28 @@
 │          [-] "const response = require('cfn-response');\nconst aws = require('aws-sdk');\nconst identity = new aws.CognitoIdentityServiceProvider();\nexports.handler = (event, context, callback) => {\n  if (event.RequestType == 'Delete') {\n    response.send(event, context, response.SUCCESS, {});\n  }\n  if (event.RequestType == 'Update' || event.RequestType == 'Create') {\n    const params = {\n      ClientId: event.ResourceProperties.clientId,\n      UserPoolId: event.ResourceProperties.userpoolId,\n    };\n    identity\n      .describeUserPoolClient(params)\n      .promise()\n      .then(res => {\n        response.send(event, 
context, response.SUCCESS, { appSecret: res.UserPoolClient.ClientSecret });\n      })\n      .catch(err => {\n        response.send(event, context, response.FAILED, { err });\n      });\n  }\n};\n"
 │          [+] {
 │          [+]   "Fn::Join": [
 │          [+]     "",
 │          [+]     [
 │          [+]       "const response = require('cfn-response');",
 │          [+]       "const aws = require('aws-sdk');",
 │          [+]       "const identity = new aws.CognitoIdentityServiceProvider();",
 │          [+]       "exports.handler = (event, context, callback) => {",
 │          [+]       " if (event.RequestType == 'Delete') { ",
 │          [+]       "   response.send(event, context, response.SUCCESS, {})",
 │          [+]       " }",
 │          [+]       " if (event.RequestType == 'Update' || event.RequestType == 'Create') {",
 │          [+]       "   const params = {",
 │          [+]       "     ClientId: event.ResourceProperties.clientId,",
 │          [+]       "     UserPoolId: event.ResourceProperties.userpoolId",
 │          [+]       "   };",
 │          [+]       "   identity.describeUserPoolClient(params).promise()",
 │          [+]       "     .then((res) => {",
 │          [+]       "       response.send(event, context, response.SUCCESS, {'appSecret': res.UserPoolClient.ClientSecret});",
 │          [+]       "     })",
 │          [+]       "     .catch((err) => {",
 │          [+]       "       response.send(event, context, response.FAILED, {err});",
 │          [+]       "     });",
 │          [+]       " }",
 │          [+]       "};"
 │          [+]     ]
 │          [+]   ]
 │          [+] }
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPoolClientRole"
        [-] ]
        [+] "UserPoolClientRole"
[~] AWS::IAM::Policy UserPoolClientLambdaPolicy 
 ├─ [~] PolicyDocument
 │   └─ [~] .Statement:
 │       └─ @@ -5,10 +5,7 @@
 │          [ ]       "cognito-idp:DescribeUserPoolClient"
 │          [ ]     ],
 │          [ ]     "Resource": {
 │          [-]       "Fn::GetAtt": [
 │          [-]         "UserPool",
 │          [-]         "Arn"
 │          [-]       ]
 │          [+]       "Fn::GetAtt": "UserPool.Arn"
 │          [ ]     }
 │          [ ]   }
 │          [ ] ]
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPoolClientLambda"
        [-] ]
        [+] "UserPoolClientLambda"
[~] AWS::IAM::Policy UserPoolClientLogPolicy 
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPoolClientLambdaPolicy"
        [-] ]
        [+] "UserPoolClientLambdaPolicy"
[~] Custom::LambdaCallout UserPoolClientInputs 
 ├─ [~] ServiceToken
 │   └─ [~] .Fn::GetAtt:
 │       └─ @@ -1,4 +1,1 @@
 │          [-] [
 │          [-]   "UserPoolClientLambda",
 │          [-]   "Arn"
 │          [-] ]
 │          [+] "UserPoolClientLambda.Arn"
 ├─ [-] DeletionPolicy
 │   └─ Delete
 ├─ [~] DependsOn
 │   └─ @@ -1,3 +1,1 @@
 │      [-] [
 │      [-]   "UserPoolClientLogPolicy"
 │      [-] ]
 │      [+] "UserPoolClientLogPolicy"
 └─ [-] UpdateReplacePolicy
     └─ Delete
[~] AWS::Cognito::IdentityPool IdentityPool 
 ├─ [~] IdentityPoolName
 │   └─ [~] .Fn::If:
 │       └─ @@ -5,7 +5,8 @@
 │          [ ] "Fn::Join": [
 │          [ ]   "",
 │          [ ]   [
 │          [-]     "dreamroirecommender17d7d821_identitypool_17d7d821__",
 │          [+]     "dreamroirecommender17d7d821_identitypool_17d7d821",
 │          [+]     "__",
 │          [ ]     {
 │          [ ]       "Ref": "env"
 │          [ ]     }
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "UserPoolClientInputs"
        [-] ]
        [+] "UserPoolClientInputs"
[~] AWS::Cognito::IdentityPoolRoleAttachment IdentityPoolRoleMap 
 └─ [~] DependsOn
     └─ @@ -1,3 +1,1 @@
        [-] [
        [-]   "IdentityPool"
        [-] ]
        [+] "IdentityPool"

Outputs
[-] Output UserPoolArn: {"Description":"Arn for the user pool","Value":{"Fn::GetAtt":["UserPool","Arn"]}}
[-] Output CreatedSNSRole: {"Description":"role arn","Value":{"Fn::GetAtt":["SNSRole","Arn"]}}
[~] Output IdentityPoolName: {"Value":{"Fn::GetAtt":["IdentityPool","Name"]}} to {"Value":{"Fn::GetAtt":"IdentityPool.Name"}}
UserPoolClientInputs.appSecret"}}

oookoook avatar Nov 18 '21 22:11 oookoook

@oookoook if you want to restore your local stack to your last successful deployment to the cloud you can run amplify env pull --restore and that should bring your local state back to what you have in the cloud.

kaustavghosh06 avatar Nov 18 '21 23:11 kaustavghosh06

Well, in YML (original definition), schema looks like this:

Schema:
        - Name: email
          Required: 'true'
          Mutable: 'true'
        - Name: phone_number
          Required: 'true'
          Mutable: 'true'

In JSON (build with 7.3.1), the schema looks like this:


"Schema": [
          {
            "Mutable": true,
            "Name": "phone_number",
            "Required": true
          }
]

Now it seems I can't add the email back...

oookoook avatar Nov 18 '21 23:11 oookoook

But I am not really sure if the user pool was updated to the state without the e-mail required:

image

oookoook avatar Nov 18 '21 23:11 oookoook

@oookoook These above attributes are immutable in the cognito service once created and cannot be updated.

kaustavghosh06 avatar Nov 18 '21 23:11 kaustavghosh06

@kaustavghosh06 well that's a good news. But CF probably thinks it successfully updated the user pool and removed the e-mail from there... That's what I see in Amplify and in CF UI in AWS as well.

One thing is that I can't deploy new versions. The other thing is that the current configuration is not working, as it does not allow authenticated users to upload files to S3. Again, the branch that went from 6.4.0 straight to 7.4.0 is perfectly fine. Right now I am looking for any kind of hack to make it work again...

oookoook avatar Nov 18 '21 23:11 oookoook

@oookoook I would pull in the environment that didn't work successfully locally and restore it back to the last successful state (by doing an amplify env pull --restore) and then run amplify push --force. Let me know what the contents of the files are (in amplify/backend/auth directory) once you locally pull in the environment which is broken.

kaustavghosh06 avatar Nov 19 '21 00:11 kaustavghosh06

@kaustavghosh06 I was able to do successful push (using CLI directly, not Amplify Console) using the YML file, from which I removed the e-mail from the Schema to match the JSON (7.3.1) version of the template.

Then I did the pull --restore, push --force and it seems we are "back on track".

I was also able to fix the problems with S3 uploads by replacing the cli-inputs.json in storage with the original CF template and parameters.json.

Thank you for your help! I wouldn't be able to fix it this fast without your advice.

oookoook avatar Nov 19 '21 10:11 oookoook

@prabha-912 - Are you still having an issue?

InnovateWithEric avatar Dec 02 '21 02:12 InnovateWithEric

I'm having the same issue on v4.51.3, and I can't update the CLI because I'm having other issues... so I'm stuck right now.

I'm wondering you could resolve this issue if you fix the amplify-codegen version to v2.26.15 or lower here. https://github.com/aws-amplify/amplify-cli/blob/2253364725bdfb336a524f1f341548a09aa3392c/packages/amplify-cli/package.json#L49

I can see an amplify-codegen peer dependency change happens on the patch release. https://github.com/aws-amplify/amplify-cli/blob/2253364725bdfb336a524f1f341548a09aa3392c/packages/amplify-cli/package.json#L49

The change probably breaks the older versions because the newer amplify-cli-core has the project but older versions don't. https://github.com/aws-amplify/amplify-cli/blob/b3ca83b9bec986f0fd525d46738b277eb93e4384/packages/amplify-cli-core/src/feature-flags/featureFlags.ts#L743-L750

The new field is assigned into the existingProjectDefaults, and ajv on the CLI throws errors if it has additional fields. https://github.com/aws-amplify/amplify-cli/blob/2253364725bdfb336a524f1f341548a09aa3392c/packages/amplify-cli-core/src/feature-flags/featureFlags.ts#L262

I still don't know why it is happening. Hopefully, this is helpful to debug the issue!

suguru03 avatar Dec 09 '21 11:12 suguru03