Skip to content

Commit 0982d8f

Browse files
authored
Use Stack ID for OriginAccessControl.Name property (#69)
* Add link to repo in template description * Derive OACConfig name from StackId * Bump version Use the Stack ID for the `OriginAccessControlConfig.Name` property. The template fails to deploy when the stack name is longer than 64 characters. The `OriginAccessControlConfig` resource fails to create, with a generic `InvalidRequest` error. The `Name` property has. a max length of 64 characters. The OriginAccessControlConfig.Name property was set to `!Sub 'oac-${AWS::StackName}-${AWS::Region}'`. For sufficiently long stack names (including the default stack name), this triggered the bug described above. `OriginAccessControlConfig` resources must have a unique `Name` across all regions for an account. To ensure this, the `Name` property was derived from both the StackName and Region. The max length of a stack name is 128 characters. This is longer than the 64 characters allowed by the OACConfig Name property.
1 parent dbf7334 commit 0982d8f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

templates/cloudfront-site.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ Resources:
103103
Type: AWS::CloudFront::OriginAccessControl
104104
Properties:
105105
OriginAccessControlConfig:
106-
Name: !Sub 'oac-${AWS::StackName}-${AWS::Region}'
106+
# Get a unique ID for the OAC Config name.
107+
# Name must be unique within account
108+
Name: !Sub
109+
- amzn-secure-static-site-${guid}
110+
- guid: !Select [2, !Split ['/', !Ref 'AWS::StackId']]
107111
OriginAccessControlOriginType: s3
108112
SigningBehavior: always
109113
SigningProtocol: sigv4

templates/main.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
AWSTemplateFormatVersion: 2010-09-09
2-
Description: ACFS3 - S3 Static site with CF and ACM (uksb-1qnk6ni7b) (version:v0.5)
2+
Description: |
3+
ACFS3 - S3 Static site with CF and ACM
4+
https://github.com/aws-samples/amazon-cloudfront-secure-static-site
5+
(uksb-1qnk6ni7b) (version:v0.5)
36
47
Metadata:
58
AWS::CloudFormation::Interface:
@@ -13,7 +16,7 @@ Metadata:
1316
Mappings:
1417
Solution:
1518
Constants:
16-
Version: 'v0.10'
19+
Version: 'v0.11'
1720

1821
Rules:
1922
OnlyUsEast1:

0 commit comments

Comments
 (0)