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

(cloudfront): failed to deploy Distribution to AWS China caused by unsupported 'CachePolicyId' #13584

Closed
zxkane opened this issue Mar 14, 2021 · 6 comments
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort p2

Comments

@zxkane
Copy link
Contributor

zxkane commented Mar 14, 2021

The deployment failed with error message,


2021-03-14 15:31:07 UTC+0800 | Distribution830FAC52 | CREATE_FAILED | The parameter CachePolicyId can't be set for this region. (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidArgument; Request ID: 682d46e9-2ccc-49ea-aeb9-57d0c508a814; Proxy: null)

Reproduction Steps

Create a distribution like below, then deploy it AWS China,

    const websiteBucket = new Bucket(this, 'DashboardUI', {
      removalPolicy: RemovalPolicy.DESTROY,
      autoDeleteObjects: true,
      encryption: BucketEncryption.S3_MANAGED,
      blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
    });

    const distribution = new Distribution(this, 'Distribution', {
      defaultBehavior: {
        origin: new S3Origin(websiteBucket),
        viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
        allowedMethods: AllowedMethods.ALLOW_GET_HEAD,
      },
      defaultRootObject: 'index.html',
      enableIpv6: false,
      priceClass: PriceClass.PRICE_CLASS_ALL,
      enableLogging: true,
    });

What did you expect to happen?

The new CloudFront distribution can be deployed to AWS China regions.

What actually happened?

Environment

  • CDK CLI Version : 1.91.0
  • Framework Version:
  • Node.js Version:
  • OS :
  • Language (Version):

Other


This is 🐛 Bug Report

@zxkane zxkane added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 14, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Mar 14, 2021
@zxkane zxkane changed the title (cloudfront): failed to deploy Distribution to AWS China (cloudfront): failed to deploy Distribution to AWS China caused by unsupported 'CachePolicyId' Mar 14, 2021
@njlynch
Copy link
Contributor

njlynch commented Mar 19, 2021

Thanks for the bug report, @zxkane.

This is because we always default to using a Cache Policy, even if one is not specified.

cachePolicyId: (this.props.cachePolicy ?? CachePolicy.CACHING_OPTIMIZED).cachePolicyId,

I can't find any documentation stating that cache policies aren't supported in CN, but from the console experience and the above report, it appears they are not (yet) supported. As a temporary work-around, you might be able to use escape hatches to remove the cache policy id. Can you try this as a work-around and see if it works?

    const distribution = new Distribution(this, 'Distribution', {
      defaultBehavior: {
        origin: new S3Origin(websiteBucket),
        viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
        allowedMethods: AllowedMethods.ALLOW_GET_HEAD,
      },
      defaultRootObject: 'index.html',
      enableIpv6: false,
      priceClass: PriceClass.PRICE_CLASS_ALL,
      enableLogging: true,
    });
    const cfnDist = (dist.node.defaultChild as CfnDistribution);
    cfnDist.addPropertyDeletionOverride('DistributionConfig.DefaultCacheBehavior.CachePolicyId');

@njlynch njlynch added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 19, 2021
@zxkane
Copy link
Contributor Author

zxkane commented Mar 26, 2021

Hi Nick,

Thanks for your workaround.

Per the doc, one of CachePolicyId and ForwardedValues is mandatory.

I have to add below overriding for a working workaround,

    cfnDist.addPropertyOverride('DistributionConfig.DefaultCacheBehavior.ForwardedValues', {
      "QueryString": false
    });

Also CachePolicy can not be used when creating CloudFront distribution in China regions. Defining cache behavior must hack the CacheBehaviors prop of distribution created by Distribution.

The old CloudFrontWebDistribution is still maintained, is it recommended for creating distribution in China regions?

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 17, 2022
@pahud
Copy link
Contributor

pahud commented Aug 6, 2024

still relevant

@pahud
Copy link
Contributor

pahud commented Aug 14, 2024

closing as the workaround #31033 (comment) is relevant.

@pahud pahud closed this as completed Aug 14, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants