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

There is already a Construct with name 'CloudFrontDomainName' in UserPoolDomain #8603

Closed
ilkomiliev opened this issue Jun 17, 2020 · 1 comment · Fixed by #8622
Closed

There is already a Construct with name 'CloudFrontDomainName' in UserPoolDomain #8603

ilkomiliev opened this issue Jun 17, 2020 · 1 comment · Fixed by #8622
Assignees
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. in-progress This issue is being actively worked on. p1

Comments

@ilkomiliev
Copy link

Trying to add the Route53 entry for the UserPoolDomain more than one time (i.e. in the public and in the private zone) in a single stack causes the below error. I think the direct cause is that the id is hard-coded in the UserPoolDomainTarget, but the indirect cause is perhaps that the construct is initialized on each call to the UserPoolDomainTarget instead to be initialized once and then cached - but it could be that I'm wrong with this assumption.

Reproduction Steps

@unique
class HostedZoneTypesEnum(Enum):
    PUBLIC = 'public'
    PRIVATE = 'private'

def register_cf_domain_name(
        self, 
        scope: core.Construct,
        user_pool_domain: aws_cognito.UserPoolDomain
    ):
        upd_target = r53_targets.UserPoolDomainTarget(user_pool_domain)
        target = r53.RecordTarget.from_alias(upd_target)
        public_zone = fr53.import_hosted_zone(scope, 'hzpublic', HostedZoneTypesEnum.PUBLIC)
        self.create_route53_a_record(
            scope=scope,
            cid='r53recpub',
            target=target,
            zone=public_zone
        )
        private_zone = fr53.import_hosted_zone(scope, 'hzprivate', HostedZoneTypesEnum.PRIVATE)
        self.create_route53_a_record(
            scope=scope,
            cid='r53recpriv',
            target=target,
            zone=private_zone
        )

    def create_route53_a_record(
        self,
        scope: core.Construct,
        cid: str,
        target: r53.RecordTarget,
        zone: HostedZoneTypesEnum
    ):
        r53.ARecord(
            scope, 
            id=cid, 
            target=target, 
            zone=zone, 
            comment='Cognito CloudFront Alias', 
            record_name=self.cognito_config.domain_name
        )

Error Log

 File "/xxx/env/lib/python3.7/site-packages/jsii/_runtime.py", line 66, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/xxx/env/lib/python3.7/site-packages/aws_cdk/aws_route53/__init__.py", line 3273, in __init__
    jsii.create(ARecord, self, [scope, id, props])
  File "/xxx/env/lib/python3.7/site-packages/jsii/_kernel/__init__.py", line 229, in create
    interfaces=[iface.__jsii_type__ for iface in getattr(klass, "__jsii_ifaces__", [])],
  File "/xxx/env/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 333, in create
    return self._process.send(request, CreateResponse)
  File "/xxx/env/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 318, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: There is already a Construct with name 'CloudFrontDomainName' in UserPoolDomain [xxx]

Environment

  • CLI Version :1.45.0 (build 0cfab15)
  • Framework Version: ?
  • Node.js Version: v10.19.0
  • OS : Amazon Linux 2
  • Language (Version): Python 3.7.6

Other

relates to #7224


This is 🐛 Bug Report

@ilkomiliev ilkomiliev added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 17, 2020
@SomayaB SomayaB added jsii This issue originates in jsii, or this feature must be implemented in jsii. @aws-cdk/aws-cognito Related to Amazon Cognito labels Jun 17, 2020
@nija-at nija-at removed the jsii This issue originates in jsii, or this feature must be implemented in jsii. label Jun 18, 2020
@nija-at nija-at changed the title jsii.errors.JSIIError: There is already a Construct with name 'CloudFrontDomainName' in UserPoolDomain There is already a Construct with name 'CloudFrontDomainName' in UserPoolDomain Jun 18, 2020
@nija-at nija-at added the p1 label Jun 18, 2020
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Jun 18, 2020
nija-at pushed a commit that referenced this issue Jun 18, 2020
…ol domain

The root cause here is that calling `cloudFrontDomainName` getter on
`UserPoolDomain` results in creating a custom resource with a fixed node
id. This resulted in the error - "There is already a Construct with name
'CloudFrontDomainName' in UserPoolDomain".

Changed the logic around so that the `CustomResource` construct is only
created on first call to the getter, and is reused on subsequent calls.

fixes #8603
@nija-at
Copy link
Contributor

nija-at commented Jun 18, 2020

Thanks for filing this issue.

The error is a bug in the underlying call to cloudFrontDomainName. I've posted a fix here - #8622

@nija-at nija-at removed @aws-cdk/aws-cloudfront Related to Amazon CloudFront needs-triage This issue or PR still needs to be triaged. labels Jun 18, 2020
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Jun 25, 2020
@mergify mergify bot closed this as completed in #8622 Jun 25, 2020
mergify bot pushed a commit that referenced this issue Jun 25, 2020
…ol domain (#8622)

The root cause here is that calling `cloudFrontDomainName` getter on
`UserPoolDomain` results in creating a custom resource with a fixed node
id. This resulted in the error - "There is already a Construct with name
'CloudFrontDomainName' in UserPoolDomain".

Changed the logic around so that the `CustomResource` construct is only
created on first call to the getter, and is reused on subsequent calls.

fixes #8603


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants