Skip to content

aws-cloudfront: default origin request policy name should include region #34336

Open
@rclark

Description

@rclark

Describe the bug

The CDK automatically appends the stack region to the name of a cache policy

const cachePolicyName = props.cachePolicyName ?? `${Names.uniqueId(this).slice(0, 110)}-${Stack.of(this).region}`;

But it does not add the region to the name of origin request policies.

const originRequestPolicyName = props.originRequestPolicyName ?? Names.uniqueId(this);

This means that an attempt to deploy the same CDK stack that includes an origin request policy into two regions can fail -- it will attempt to create a policy with the same name in both regions, which is not allowed.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

A behavior defined like this should be able to be deployed into more than one region in the same account without naming conflicts on either the cache policy or origin request policy.

        aws_cloudfront.BehaviorOptions(
            cache_policy=aws_cloudfront.CachePolicy(
                self,
                "cache-policy",
                ...
            ),
            origin_request_policy=aws_cloudfront.OriginRequestPolicy(
                self,
                "origin-request-policy",
                ...
            ),
            ...
    )

Current Behavior

I attempted such a deploy across 5 regions. The expectation being that the deploy in each region would set up a regional origin and a CloudFront distribution specifically for that regional origin. One of the deployments succeeded -- the first one that created the origin request policy. The other 4 failed because they tried to create one with the same name.

Reproduction Steps

see above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.1010.0 (build 6b421db)

Framework Version

No response

Node.js Version

OS

Language

Python

Language Version

Python 3.12.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-cloudfrontRelated to Amazon CloudFrontbugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions