cloudcomponents / cdk-constructs

A collection of higher-level reusable cdk constructs
MIT License
625 stars 104 forks source link

StaticSiteDistribution, impossible to update User Pool Client Callbacks #133

Closed danielesalvatore closed 2 years ago

danielesalvatore commented 2 years ago

Dear all, Thank you very much for this instrumental project.

I report here an issue I experienced while using StaticSiteDistribution and trying to update the User Pool Client Callbacks. It seems that to use the updateUserPoolClientCallbacks(redirects) method break the synth process due to the following error, which appears related to an ID duplication inside the StaticSiteAuthorization construct:

jsii.errors.JSIIError: There is already a Construct with name 'UserPoolClientRedirects' in StaticSiteAuthorization [Authorization]

I paste below the relevant part of my python code to show how I am using the construct, with an already existing Cognito User Pool and an existing S3 bucket.

  user_pool = _cognito.UserPool.from_user_pool_arn(
      self, "UserPool", user_pool_arn=user_pool_arn)

  authorization = StaticSiteAuthorization(self, "Authorization",
      user_pool=user_pool
  )

  # This is where the mentioned error is thrown 
  authorization.update_user_pool_client_callbacks(
      callback_urls=["https//{0}/parseauth".format(bucket_name)], 
      logout_urls=["https//{0}/".format(bucket_name)]
      )

  static_distribution = StaticSiteDistribution(self, "Distribution",
      authorization=authorization,
      origin=origins.S3Origin(self.bucket)
  )

Am I using incorrectly the component or do you think this is an internal bug of the construct?

Thanks in advance! Daniele

hupe1980 commented 2 years ago

The Api is really a bit confusing...

You can pass the bucket name as a domain name

static_distribution = StaticSiteDistribution(self, "Distribution",
      authorization=authorization,
      domainNames=[bucket_name],
      origin=origins.S3Origin(self.bucket)
  )

https://github.com/cloudcomponents/cdk-constructs/blob/9068b37dbed2e5b15c1148f633d1aecf24541adb/packages/cdk-cloudfront-authorization/src/distributions.ts#L199-L206).

danielesalvatore commented 2 years ago

It worked thanks!