How pass json value for admin-update-user-attributes operation via cli in aws?

醉酒当歌 提交于 2021-02-09 11:19:07

问题


Consider the example:

aws cognito-idp admin-update-user-attributes --user-pool-id myUserPollId
--username myUser 
--user-attributes [{"Name": "custom:roles","Value": "ROLE1,ROLE2"}] --region us-east-1

This gets me error:

Invalid JSON:
    [{Name:

回答1:


  1. You can always try using shorthand syntax:

    --user-attributes Name="custom:roles",Value="ROLE1,ROLE2"
  2. If you really want to use the JSON syntax, try this:

    --user-attributes '[{"Name" : "custom:roles","Value" : "ROLE1,ROLE2"}]'
    • Ensure that the user-attributes list is enclosed in single quotes



回答2:


--user-attributes '[{"Name": "phone_number", "Value": "+123434532"}, 
{"Name": "name", "Value":"name_your"}]'



回答3:


In case someone get stuck in the same problem again, below are the tested steps to have user attributes updated via aws cli with json file.

Step 0: Setup AWS CLI in case you haven't already. Mac users can run:

brew install awscli

Step 1: Have a valid json handy with you, saved in a file. Sample json with valid format:

{
  "UserAttributes": [{
      "Name": "custom:additional-attribute1",
      "Value": "Value for additional attribute 1"
    },
    {
      "Name": "custom:additional-attribute2",
      "Value": "Value for additional attribute 2"
    }
  ]
}

Step 2: Run the following in your console:

aws cognito-idp admin-update-user-attributes --user-pool-id XX-XXXX-X_XXXXXXXXX --username XXXXX@XXXXX.com --cli-input-json file:///Users/YOUR_PATH_TO_THE_FILE/user-attributes.json

Parameters:

--user-pool-id :: Your user pool ID.
--username :: The user you want to udpate.
--cli-input-json :: This is the command that loads json file and parses it.

That's it. If your json is valid and aws cli authorises, the given user record should be updated instantly.



来源:https://stackoverflow.com/questions/47429352/how-pass-json-value-for-admin-update-user-attributes-operation-via-cli-in-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!