We have a CF distribution that is used for caching responses from MediaPackage. We have multiple MediaPackage endpoints and for each endpoint there is a corresponding origin/behavior on the same CF distribution.
Using CDK how can we add a new origin/behavior on the existing CF distribution?. I tried below but ran into an error:
// load existing distribution
const distribution = Distribution.fromDistributionAttributes(scope, `${props.stackName}-Distribution`, {
distributionId: 'E33333B',
domainName: 'test.example.com'
}) as Distribution;
// Convert to CfnDistribution
const distributionLive = distribution.node.defaultChild as CfnDistribution;
const distributionConfig =
distributionLive.distributionConfig as CfnDistribution.DistributionConfigProperty;
// Fetch origin/behaviors list
const cacheBehaviors = distributionConfig.cacheBehaviors as CfnDistribution.CacheBehaviorProperty[];
const origins = distributionConfig.origins as CfnDistribution.OriginProperty[];
// Add new origin/behavior
origins.push({..})
cacheBehaviors.push({..})
Error:
/dist/lib/resources/cloudfront.js:95
const distConfig = distributionLive.distributionConfig;
^
TypeError: Cannot read property 'distributionConfig' of undefined