aws-cloudfront: default origin request policy name should include region
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
The CDK automatically appends the stack region to the name of a cache policy
https://github.com/aws/aws-cdk/blob/a81326ea32d8cc499d160a16acbdc677e1d2b1b7/packages/aws-cdk-lib/aws-cloudfront/lib/cache-policy.ts#L148
But it does not add the region to the name of origin request policies.
https://github.com/aws/aws-cdk/blob/a81326ea32d8cc499d160a16acbdc677e1d2b1b7/packages/aws-cdk-lib/aws-cloudfront/lib/origin-request-policy.ts#L97
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.
```py
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_
Contributor guide
Research direction
Compare packages/aws-cdk-lib/aws-cloudfront/lib/cache-policy.ts at the referenced line with packages/aws-cdk-lib/aws-cloudfront/lib/origin-request-policy.ts. Start by tracing how each policy name is formed, then verify that origin request policy names include the stack region so identical stacks can deploy across regions without naming conflicts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100