项目作者: michaelduminy

项目描述 :
Add custom attributes to an existing CloudFormation-managed CognitoUserPool from serverless without losing all your users
高级语言: JavaScript
项目地址: git://github.com/michaelduminy/serverless-cognito-add-custom-attributes.git
创建时间: 2018-06-15T09:07:34Z
项目社区:https://github.com/michaelduminy/serverless-cognito-add-custom-attributes

开源协议:MIT License

下载


npm version

serverless-cognito-add-custom-attributes

This plugin allows you to add custom attributes to an existing CloudFormation-managed Cognito User Pool from serverless without losing all your users. At the time of writing (June 2018) CloudFormation doesn’t know how to add custom attributes to a user pool without dropping and re-creating it, thus losing all your users.

This plugin also adds the specified attributes to a User Pool Client, giving that client read and write permissions for the new attribute.

Requirements

  • Node 8+
  • serverless 1+

Usage

Install npm i serverless-cognito-add-custom-attributes, then add serverless-cognito-add-custom-attributes to your serverless.yml plugins list.

  1. plugins:
  2. - serverless-cognito-add-custom-attributes
  3. custom:
  4. CognitoAddCustomAttributes:
  5. CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId" # The key of the outputted UserPool Ref
  6. CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId" # The key of the outputted UserPoolClient Ref
  7. CustomAttributes:
  8. -
  9. AttributeDataType: String
  10. DeveloperOnlyAttribute: False
  11. Mutable: True
  12. Name: "another" # this will end up being custom:another
  13. Required: False
  14. # Only add this if not already outputting the Cognito User Pool and Client IDs, otherwise, refer to the existing outputs in the custom:CognitoAddCustomAttributes section
  15. resources:
  16. Outputs:
  17. CognitoUserPoolApplicationUserPoolId:
  18. Value:
  19. Ref: CognitoUserPoolApplicationUserPool
  20. CognitoUserPoolApplicationUserPoolClientId:
  21. Value:
  22. Ref: CognitoUserPoolApplicationUserPoolClient

Details

  1. Output your UserPoolId via resources.Outputs
  2. Output your UserPoolClientId via resources.Outputs
  3. Add CognitoAddCustomAttributes to custom with the following structure:
    1. CognitoUserPoolIdOutputKey: "UserPool Output Key as a String"
    2. CognitoUserPoolClientIdOutputKey: "UserPoolClient Output Key as a String"
    3. CustomAttributes:
    4. -
    5. AttributeDataType: String
    6. DeveloperOnlyAttribute: False
    7. Mutable: True
    8. Name: "another"
    9. Required: False

Note: If you have multiple userPool-userPoolClients you can specify them as an array as well

Example:

  1. plugins:
  2. - serverless-cognito-add-custom-attributes
  3. custom:
  4. CognitoAddCustomAttributes:
  5. -
  6. CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId"
  7. CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId"
  8. CustomAttributes:
  9. -
  10. AttributeDataType: String
  11. DeveloperOnlyAttribute: False
  12. Mutable: True
  13. Name: "another" # this will end up being custom:another
  14. Required: False
  15. -
  16. CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId"
  17. CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId2"
  18. CustomAttributes:
  19. -
  20. AttributeDataType: String
  21. DeveloperOnlyAttribute: False
  22. Mutable: True
  23. Name: "another" # this will end up being custom:another
  24. Required: False
  25. resources:
  26. Outputs:
  27. CognitoUserPoolApplicationUserPoolId:
  28. Value:
  29. Ref: CognitoUserPoolApplicationUserPool
  30. CognitoUserPoolApplicationUserPoolClientId:
  31. Value:
  32. Ref: CognitoUserPoolApplicationUserPoolClient
  33. CognitoUserPoolApplicationUserPoolClientId2:
  34. Value:
  35. Ref: CognitoUserPoolApplicationUserPoolClient2

The names of your attributes supplied here will appear as custom:{name} when deployed.

For more information on the schema of attributes see:
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SchemaAttributeType.html