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

feat(cognito): add analyticsConfiguration to UserPoolClient #32862

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

ren-yamanashi
Copy link
Contributor

Issue # (if applicable)

Closes #32837

Reason for this change

UserPoolClient in Cognito did not support the analyticsConfiguration property.

Description of changes

  • add analytics property to UserPoolClientProps(interface)
  • add validationAnalytics method to UserPoolClient(Class / L2 Construct)

Description of how you validated changes

Added both unit and integration tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team January 12, 2025 09:13
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels Jan 12, 2025
@ren-yamanashi ren-yamanashi changed the title feat: add analyticsConfiguration to UserPoolClient feat(cognito): add analyticsConfiguration to UserPoolClient Jan 12, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 12, 2025 09:33

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.38%. Comparing base (a734841) to head (5ca76ad).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32862   +/-   ##
=======================================
  Coverage   81.38%   81.38%           
=======================================
  Files         222      222           
  Lines       13695    13695           
  Branches     2412     2412           
=======================================
  Hits        11145    11145           
  Misses       2271     2271           
  Partials      279      279           
Flag Coverage Δ
suite.unit 81.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.69% <ø> (ø)
packages/aws-cdk-lib/core 82.09% <ø> (ø)

@ren-yamanashi ren-yamanashi changed the title feat(cognito): add analyticsConfiguration to UserPoolClient feat(cognito): add analyticsConfiguration to UserPoolClient [WIP] Jan 12, 2025
Copy link
Contributor

@wladyslawczyzewski wladyslawczyzewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @ren-yamanashi , thank you for this contribution, could you please adjust the validation and tests as described in the comments? thank you in advance!

@@ -618,4 +667,13 @@ export class UserPoolClient extends Resource implements IUserPoolClient {
throw new Error(`${name}: Must be a duration between ${min.toHumanString()} and ${max.toHumanString()} (inclusive); received ${value.toHumanString()}.`);
}
}

private validateAnalytics(analytics: AnalyticsConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the CloudFormation expects either ApplicationArn or all of ApplicationId, ExternalId and RoleArn to be provided. Could you please adjust the validation for this?

// resources: [pinpointApp.attrArn],
// }));

new UserPoolClient(stack, 'Client', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloud you please provide more test cases for 1) providing only ApplicationArn and using the Cognito's service role and 2) providing all of ApplicationId, ExternalId and RoleArn?

@ren-yamanashi
Copy link
Contributor Author

ren-yamanashi commented Jan 12, 2025

hi @ren-yamanashi , thank you for this contribution, could you please adjust the validation and tests as described in the comments? thank you in advance!

@wladyslawczyzewski

Thank you comment !

I will adjust the PR content based on your comment and #32865 🙏.

@ren-yamanashi ren-yamanashi changed the title feat(cognito): add analyticsConfiguration to UserPoolClient [WIP] feat(cognito): add analyticsConfiguration to UserPoolClient Jan 12, 2025
If you specify the `applicationArn` property, do not specify the `applicationId`, `externalId`, or `roleArn` properties.

```ts
import * as pinpoint from 'aws-cdk-lib/aws-pinpoint';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following error occurs at build time, so the import statement is added.

aws-cdk-lib.aws_cognito-README-L1123.ts:4:28 - error TS2503: Cannot find namespace 'pinpoint'.

4 declare const pinpointApp: pinpoint.CfnApp;

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 13, 2025
Copy link
Contributor

mergify bot commented Jan 13, 2025

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5ca76ad
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@wladyslawczyzewski wladyslawczyzewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your work on this! all looks good to me, now waiting for someone from maintainers to review and merge 🤞

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 Left comments for some initial adjustments.

analytics.applicationArn &&
(analytics.applicationId || analytics.externalId || analytics.role)
) {
throw new Error('Either `applicationArn` or all of `applicationId`, `externalId` and `role` must be specified.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide some docs/explanation about this validation?

Comment on lines +366 to +368
* The settings for Amazon Pinpoint analytics configuration.\
* With an analytics configuration, your application can collect user-activity metrics for user notifications with a Amazon Pinpoint campaign.\
* Amazon Pinpoint isn't available in all AWS Regions. For a list of available Regions, see [Amazon Cognito and Amazon Pinpoint Region availability](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html#cognito-user-pools-find-region-mappings).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The settings for Amazon Pinpoint analytics configuration.\
* With an analytics configuration, your application can collect user-activity metrics for user notifications with a Amazon Pinpoint campaign.\
* Amazon Pinpoint isn't available in all AWS Regions. For a list of available Regions, see [Amazon Cognito and Amazon Pinpoint Region availability](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html#cognito-user-pools-find-region-mappings).
* The settings for Amazon Pinpoint analytics configuration.
* With an analytics configuration, your application can collect user-activity metrics for user notifications with an Amazon Pinpoint campaign.
* Amazon Pinpoint isn't available in all AWS Regions.
* For a list of available Regions, see [Amazon Cognito and Amazon Pinpoint Region availability](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html#cognito-user-pools-find-region-mappings).

Formatting.

Comment on lines +372 to +373
* The Amazon Resource Name (ARN) of an Amazon Pinpoint project that you want to connect to your user pool app client.\
* Amazon Cognito publishes events to the Amazon Pinpoint project that `ApplicationArn` declares. You can also configure your application to pass an endpoint ID in the `AnalyticsMetadata` parameter of sign-in operations. The endpoint ID is information about the destination for push notifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The Amazon Resource Name (ARN) of an Amazon Pinpoint project that you want to connect to your user pool app client.\
* Amazon Cognito publishes events to the Amazon Pinpoint project that `ApplicationArn` declares. You can also configure your application to pass an endpoint ID in the `AnalyticsMetadata` parameter of sign-in operations. The endpoint ID is information about the destination for push notifications
* The Amazon Resource Name (ARN) of an Amazon Pinpoint project that you want to connect to your user pool app client.
* Amazon Cognito publishes events to the Amazon Pinpoint project that `ApplicationArn` declares.
* You can also configure your application to pass an endpoint ID in the `AnalyticsMetadata` parameter of sign-in operations.
* The endpoint ID is information about the destination for push notifications.

Formatting

readonly role?: IRole;

/**
* If `UserDataShared` is `true` , Amazon Cognito includes user data in the events that it publishes to Amazon Pinpoint analytics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If `UserDataShared` is `true` , Amazon Cognito includes user data in the events that it publishes to Amazon Pinpoint analytics.
* If `true`, Amazon Cognito includes user data in the events that it publishes to Amazon Pinpoint analytics.

Formatting.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cognito): L2 Construct support for analytics configuration
4 participants