Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognito: Custom Invite Message Template omits EmailMessage in sythed template #30315

Closed
dreams-and-thoughts opened this issue May 23, 2024 · 6 comments
Assignees
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug.

Comments

@dreams-and-thoughts
Copy link

dreams-and-thoughts commented May 23, 2024

Describe the bug

When creating a custom Invite Message template:

const invite
MessageTemplateProperty: cognito.CfnUserPool.InviteMessageTemplateProperty = {
    emailSubject: 'email subject test',
    emailMessage: 'email body test',
    smsMessage: 'sms test'
}

The template output result is missing the EmailMessage property:

AdminCreateUserConfig:
    AllowAdminCreateUserOnly: true
    InviteMessageTemplate:
      EmailSubject: email subject test
      SMSMessage: sms test

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-invitemessagetemplate.html

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-invitemessagetemplate.html#cfn-cognito-userpool-invitemessagetemplate-emailmessage

Expected Behavior

The final stack output template should contain the customized EmailMessage property.

Current Behavior

The output template does not contain the custom EmailMessage property.

Cognito console Messaging section is updated with the new custom SMS and Email subject, but the invite email body remains unchanged from the default.

Reproduction Steps

Create a stack with the following:

const inviteMessageTemplateProperty: cognito.CfnUserPool.InviteMessageTemplateProperty = {
    emailSubject: 'email subject test',
    emailMessage: 'email body test',
    smsMessage: 'sms test'
}

const userPool = new cognito.UserPool(this, 'user-pool', {
    userPoolName: 'userpool',
    selfSignUpEnabled: false,
    enableSmsRole: false,
    accountRecovery: AccountRecovery.EMAIL_ONLY,
    customAttributes: {
        roles: new StringAttribute({
            minLen: 0,
            maxLen: 2048
        })
    },
    userInvitation: inviteMessageTemplateProperty
})

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.141.0 (build 3d1c06e)

Framework Version

No response

Node.js Version

v18.14.1

OS

mac

Language

TypeScript

Language Version

No response

Other information

No response

@dreams-and-thoughts dreams-and-thoughts added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 23, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label May 23, 2024
@dreams-and-thoughts
Copy link
Author

Looks to be same problem with VerificationMessageTemplateProperty > EmailVerificationMessage as well.

Subject works as expected, message body is dropped from the output template.

@ashishdhingra ashishdhingra self-assigned this May 23, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels May 23, 2024
@ashishdhingra
Copy link
Contributor

@dreams-and-thoughts Good morning. Upon investigation, looks like you are using incorrect userInvitation (and/or userVerification structure).

  • Per UserInvitationConfig interface documentation, the property names are emailBody, emailSubject and smsMessage). Instead you are using emailMessage as the property, hence it is dropped. When the stack is synthesized, emailBody property value is mapped to emailMessage property here.
    (in your case, emailSubject and smsMessage worked since these are similarly named to expected properties in UserInvitationConfig interface)
  • Same reasoning goes for userVerification structure per documentation for UserVerificationConfig.

So when we use the below stack with expected properties per documentation, the emailBody is reflected in output CFN template as emailMessage property:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as cognito from 'aws-cdk-lib/aws-cognito';

export class Issue30315CognitoStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const userPool = new cognito.UserPool(this, 'user-pool', {
      userPoolName: 'userpool',
      selfSignUpEnabled: false,
      enableSmsRole: false,
      accountRecovery: cognito.AccountRecovery.EMAIL_ONLY,
      customAttributes: {
        roles: new cognito.StringAttribute({
          minLen: 0,
          maxLen: 2048
        })
      },
      userInvitation: {
        emailBody: "Test user invitation email body.",
        emailSubject: "Test user invitation email subject.",
        smsMessage: "Test user invitation SMS message."
      }
    });
  }
}

Output CFN template:

Resources:
  userpool38E431F2:
    Type: AWS::Cognito::UserPool
    Properties:
      AccountRecoverySetting:
        RecoveryMechanisms:
          - Name: verified_email
            Priority: 1
      AdminCreateUserConfig:
        AllowAdminCreateUserOnly: true
        InviteMessageTemplate:
          EmailMessage: Test user invitation email body.
          EmailSubject: Test user invitation email subject.
          SMSMessage: Test user invitation SMS message.
      EmailVerificationMessage: The verification code to your new account is {####}
      EmailVerificationSubject: Verify your new account
      Schema:
        - AttributeDataType: String
          Name: roles
          StringAttributeConstraints:
            MaxLength: "2048"
            MinLength: "0"
      SmsVerificationMessage: The verification code to your new account is {####}
      UserPoolName: userpool
      VerificationMessageTemplate:
        DefaultEmailOption: CONFIRM_WITH_CODE
        EmailMessage: The verification code to your new account is {####}
        EmailSubject: Verify your new account
        SmsMessage: The verification code to your new account is {####}
    UpdateReplacePolicy: Retain
    DeletionPolicy: Retain
    Metadata:
      aws:cdk:path: Issue30315CognitoStack/user-pool/Resource
...
...

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-reproduction This issue needs reproduction. labels May 23, 2024
@pahud
Copy link
Contributor

pahud commented May 23, 2024

Hi,

You should not assign userInvitation with a L1 interface like that.

If you use VSCode you can trigger parameter hints like this and you should see the emailBody is required for that.

image

And per @ashishdhingra mentioned in the source code, it maps to EmailMessage under the hood.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 23, 2024
@dreams-and-thoughts
Copy link
Author

dreams-and-thoughts commented May 24, 2024

Great, got it. Thanks very much.

Always been a bit confused by the CDK interface/types vs the L1 Cloudformation structures.

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants