question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Acessing the 'DistributionConfig' of the 'CfnDistribution_' throws an error

See original GitHub issue

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository’s issues are intended for feature requests and bug reports.

  • I’m submitting a …

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior? If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

Create a new CloudFrontWebDistribution, var cf = new CloudFrontWebDistribution Access the underlying CfnDistribution_ with var cfd = cf.Node.FindChild("CFDistribution") as CfnDistribution_; Acessing the DistributionConfig of the CfnDistribution_ throws an error:

Got 'undefined' for non-optional instance of {"abstract":true,"docs":{"remarks":"If this returns an empty array the stack will not be attached.","stability":"stable","summary":"The creation stack of this resolvable which will be appended to errors thrown during resolution."},"immutable":true,"locationInModule":{"filename":"lib/resolvable.ts","line":38},"name":"creationStack","type":{"collection":{"elementtype":{"primitive":"string"},"kind":"array"}}}
  • What is the expected behavior (or behavior of feature suggested)?

To be able to see the DistributionConfig of the CfnDistribution_

  • What is the motivation / use case for changing the behavior or adding this feature?

I was trying to work around other bugs in the CloudFrontWebDistribution by accessing the DistributionConfig to modify and add it back as overrides

  • Please tell us about your environment:

    • CDK CLI Version: 0.39
    • Module Version: 0.39
    • OS: [Windows 10]
    • Language: [C#]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc) Stacktrace:

Got 'undefined' for non-optional instance of {"abstract":true,"docs":{"remarks":"If this returns an empty array the stack will not be attached.","stability":"stable","summary":"The creation stack of this resolvable which will be appended to errors thrown during resolution."},"immutable":true,"locationInModule":{"filename":"lib/resolvable.ts","line":38},"name":"creationStack","type":{"collection":{"elementtype":{"primitive":"string"},"kind":"array"}}}

   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Deputy.DeputyBase.GetPropertyCore[T](JsiiPropertyAttribute propertyAttribute, Func`2 getFunc)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
McDoitcommented, Oct 29, 2020

I’ve created aws/jsii#2192 to introduce an UnsafeCast<T>() method on DeputyBase (the parent class of AnonymousObject) to allow casting to an arbitrary interface type.

This would allow you to write something along the lines of:

var dcp = (cfd.DistributionConfig as DeputyBase).UnsafeCast<CfnDistribution.DistributionConfigProperty>();

Effectively un-blocking your use-case (and other use-cases that involve property overrides with complex/composite properties).

This might become more elegant in the future, as type unions are supported better (more info at aws/aws-cdk-rfcs#193).

I tried it with CDK 1.70 and JSII 1.14, but I got the following error running the repro stack above: System.InvalidCastException: 'Unable to cast Amazon.JSII.Runtime.Deputy.AnonymousObject into Amazon.CDK.AWS.CloudFront.CfnDistribution+DistributionConfigProperty'

1reaction
njlynchcommented, Oct 16, 2020

I verified; just reproduced the above errors (Amazon.JSII.Runtime.Deputy.AnonymousObject/NPE) on CDK 1.68.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class CfnDistribution (construct) · AWS CDK
A complex type that contains zero or more Tag elements. distributionConfig. Type: IResolvable | DistributionConfigProperty. The current configuration ...
Read more >
awslabs/aws-cdk - Gitter
Does anyone know how to override CFT array in CDK using . ... if (masterSecretArn == 'missing') { throw new Error('You must provide...
Read more >
504 Error for Cloudfront.net distribution and Route53 Domain
When I access my static s3 bucket via xyz-cloud-website.s3-website-us-east-1.amazonaws.com, I have no issues. It's only when I try to use my ...
Read more >
get-distribution-config — AWS CLI 2.9.9 Command Reference
If you want viewers to be able to access objects using either the CloudFront URL or the Amazon S3 URL, specify an empty...
Read more >
Managing Amazon CloudFront distributions using the ...
For more information about using Amazon CloudFront, see the Amazon CloudFront Developer ... return $message; } catch (AwsException $e) { return 'Error: '...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found