-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
cloudfront: CachePolicy is not supported when deployed in China #31033
Comments
Yes #13584 is still relevant. I just reopened it. We need a PR to address that. |
internal tracking: V1476577865 |
Hi @Chenming88 We are still pending for the response from cloudfront team before we know how to address that for China regions with #31038. Before we fix this issue from there, I guess you could write a CDK Aspect to override or remove the I don't have immediate sample for that but this could be a workaround. Check out here for the doc of CDK Aspects. |
Thanks for your help, I found a way to handle LazyAny type using Aspects, which is my way around. // Later, apply to the stack
Aspects.of(this).add({
visit(node: IConstruct) {
if (node instanceof CfnDistribution) {
const distributionConfig = node.distributionConfig as CfnDistribution.DistributionConfigProperty;
const resolvedCacheBehaviorsDefs = cdk.Stack.of(node).resolve(distributionConfig.cacheBehaviors) as CfnDistribution.CacheBehaviorProperty[];
node.distributionConfig = {
...distributionConfig,
cacheBehaviors: resolvedCacheBehaviorsDefs.map(cacheBehavior => {
return {
...cacheBehavior,
cachePolicyId: undefined,
forwardedValues: { queryString: false },
defaultTtl: cdk.Duration.days(1).toSeconds(),
minTtl: cdk.Duration.hours(1).toSeconds(),
maxTtl: cdk.Duration.days(365).toSeconds(),
}
}),
}
}
}
}); |
Hi This works for me as well: export class DummyStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const origin = defaultOrigin();
const dist = new cloudfront.Distribution(this, 'MyDist', { defaultBehavior: { origin } });
const cfndist = dist.node.defaultChild as cloudfront.CfnDistribution;
cfndist.addPropertyDeletionOverride('DistributionConfig.DefaultCacheBehavior.CachePolicyId');
cfndist.addPropertyOverride('DistributionConfig.DefaultCacheBehavior.ForwardedValues', {
"QueryString": false
});
}
}
MyDistDB88FD9A:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
Compress: true
ForwardedValues:
QueryString: false
TargetOriginId: dummystack7MyDistOrigin1E2CDA54E
ViewerProtocolPolicy: allow-all
Enabled: true
HttpVersion: http2
IPV6Enabled: true
Origins:
- CustomOriginConfig:
OriginProtocolPolicy: https-only
DomainName: www.example.com
Id: dummystack7MyDistOrigin1E2CDA54E Let me know if this works for you. related to #13584 (comment) |
@pahud For multiple |
Describe the bug
AWS China does not support CachePolicy, but a default value is assigned in the cdk, causing the deployment to fail. #13584
I use the way I override
cachePolicyId=underfined
, which works fordefaultCacheBehavior
, but because I need to use multiple Behaviors.cacheBehaviors
return is a LazyAny type and can't be overwritten, which makes it impossible to circumvent aws restrictions. I hope you can fix this bug, thank you very much.Expected Behavior
The new CloudFront distribution can be deployed to AWS China regions.
Current Behavior
Reproduction Steps
Possible Solution
No response
Additional Information/Context
Because the cacheBehaviors type is LazyAny, it is not rewrite successfully, resulting in the same error
CDK CLI Version
2.123.0
Framework Version
No response
Node.js Version
v18.14.1
OS
mac
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: