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: Remove custom resource from UserPoolDomain to get CloudFrontDistribution attribute #31342

Closed
2 tasks
tmokmss opened this issue Sep 6, 2024 · 3 comments · Fixed by #31402
Closed
2 tasks
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Sep 6, 2024

Describe the feature

Currently we use an AwsCutstomResource to get cloudFrontDomainName attribute for a UserPoolDomain resource.

public get cloudFrontDomainName(): string {
if (!this.cloudFrontCustomResource) {
const sdkCall: AwsSdkCall = {
service: 'CognitoIdentityServiceProvider',
action: 'describeUserPoolDomain',
parameters: {
Domain: this.domainName,
},

But actually CFn exposes the attribute natively. We can remove the unnecessary custom resource usage.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpooldomain.html#aws-resource-cognito-userpooldomain-return-values

Use Case

To get a CloudFront domain for a user pool domain without using a custom resource. c.f. https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html

Proposed Solution

We can just replace it with a getAtt call.

  public get cloudFrontDomainName(): string {
    return resource.getAtt('CloudFrontDistribution').toString(),
  }

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.155.0

Environment details (OS name and version, etc.)

macOS

@tmokmss tmokmss added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 6, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Sep 6, 2024
@ashishdhingra ashishdhingra self-assigned this Sep 6, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 6, 2024
@ashishdhingra
Copy link
Contributor

Yes, it makes sense to remove usage of custom resource given that CloudFrontDistribution could be obtained from Fn::GetAtt. We would also need to store resource reference in a private field.

The following code works:

import * as cdk from 'aws-cdk-lib';
import * as cognito from 'aws-cdk-lib/aws-cognito';


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

    const userPool = cognito.UserPool.fromUserPoolId(this, 'userpool', 'us-east-2_G27QXonjy');
    
    const resource = new cognito.CfnUserPoolDomain(this, 'Resource', {
      userPoolId: userPool.userPoolId,
      domain: 'myexampledomain'
    });

    const cloudFrontDistribution = resource.getAtt('CloudFrontDistribution');
    new cdk.CfnOutput(this, 'CloudFrontDistribution', { value: cloudFrontDistribution.toString()});
  }
}

produces the below output during cdk deploy:

✨  Synthesis time: 4.44s

CdktestStack:  start: Building 3d7f64ff11c6c4f29991c464279067ff6118a2f56e5e24e568922a6fc616da65:139480602983-us-east-2
CdktestStack:  success: Built 3d7f64ff11c6c4f29991c464279067ff6118a2f56e5e24e568922a6fc616da65:139480602983-us-east-2
CdktestStack:  start: Publishing 3d7f64ff11c6c4f29991c464279067ff6118a2f56e5e24e568922a6fc616da65:139480602983-us-east-2
CdktestStack:  success: Published 3d7f64ff11c6c4f29991c464279067ff6118a2f56e5e24e568922a6fc616da65:139480602983-us-east-2
CdktestStack: deploying... [1/1]
CdktestStack: creating CloudFormation changeset...

 ✅  CdktestStack

✨  Deployment time: 18.79s

Outputs:
CdktestStack.CloudFrontDistribution = d1lcia0inyjsq.cloudfront.net
Stack ARN:
arn:aws:cloudformation:us-east-2:139480602983:stack/CdktestStack/ad8fa120-6f9b-11ef-8dd4-02a04ad84bdd

✨  Total time: 23.24s

@ashishdhingra ashishdhingra added effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. effort/medium Medium work item – several days of effort labels Sep 10, 2024
@ashishdhingra ashishdhingra removed their assignment Sep 10, 2024
@mergify mergify bot closed this as completed in #31402 Nov 27, 2024
@mergify mergify bot closed this as completed in deeb2ad Nov 27, 2024
Copy link

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.

1 similar comment
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 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 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
2 participants