You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
plugins:
- serverless-cognito-add-custom-attributescustom:
CognitoAddCustomAttributes:
CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId"# The key of the outputted UserPool Ref CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId"# The key of the outputted UserPoolClient RefCustomAttributes:
-
AttributeDataType: StringDeveloperOnlyAttribute: FalseMutable: TrueName: "another"# this will end up being custom:anotherRequired: False# Only add this if not already outputting the Cognito User Pool and Client IDs, otherwise, refer to the existing outputs in the custom:CognitoAddCustomAttributes sectionresources:
Outputs:
CognitoUserPoolApplicationUserPoolId:
Value:
Ref: CognitoUserPoolApplicationUserPoolCognitoUserPoolApplicationUserPoolClientId:
Value:
Ref: CognitoUserPoolApplicationUserPoolClient
Details
Output your UserPoolId via resources.Outputs
Output your UserPoolClientId via resources.Outputs
Add CognitoAddCustomAttributes to custom with the following structure:
CognitoUserPoolIdOutputKey: "UserPool Output Key as a String"CognitoUserPoolClientIdOutputKey: "UserPoolClient Output Key as a String"CustomAttributes:
-
AttributeDataType: StringDeveloperOnlyAttribute: FalseMutable: TrueName: "another"Required: False
Note: If you have multiple userPool-userPoolClients you can specify them as an array as well
Example:
plugins:
- serverless-cognito-add-custom-attributescustom:
CognitoAddCustomAttributes:
-
CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId"CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId"CustomAttributes:
-
AttributeDataType: StringDeveloperOnlyAttribute: FalseMutable: TrueName: "another"# this will end up being custom:anotherRequired: False
-
CognitoUserPoolIdOutputKey: "CognitoUserPoolApplicationUserPoolId"CognitoUserPoolClientIdOutputKey: "CognitoUserPoolApplicationUserPoolClientId2"CustomAttributes:
-
AttributeDataType: StringDeveloperOnlyAttribute: FalseMutable: TrueName: "another"# this will end up being custom:anotherRequired: Falseresources:
Outputs:
CognitoUserPoolApplicationUserPoolId:
Value:
Ref: CognitoUserPoolApplicationUserPoolCognitoUserPoolApplicationUserPoolClientId:
Value:
Ref: CognitoUserPoolApplicationUserPoolClientCognitoUserPoolApplicationUserPoolClientId2:
Value:
Ref: CognitoUserPoolApplicationUserPoolClient2
The names of your attributes supplied here will appear as custom:{name} when deployed.