Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit 8866dc1

Browse files
Adding Suppor for Creating Static S3 Sites
**This change addresses the need by:** * closes #71 Signed-off-by: Christopher Hein <[email protected]>
1 parent cdd6871 commit 8866dc1

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

cloudformation/s3bucket.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ Parameters:
7373
- BucketOwnerFullControl
7474
- AwsExecRead
7575
Default: "Private"
76+
EnableStaticSite:
77+
Description: enable static site
78+
Type: String
79+
AllowedValues:
80+
- 'true'
81+
- 'false'
82+
Default: 'false'
83+
StaticSiteIndex:
84+
Description: Index document for the S3 bucket static site
85+
Type: String
86+
Default: 'index.html'
87+
StaticSiteError:
88+
Description: Error document for the S3 bucket static site
89+
Type: String
90+
Default: "500.html"
7691
Mappings: {}
7792
Conditions:
7893
UseLogging: !Equals
@@ -84,12 +99,20 @@ Conditions:
8499
UseVersioning: !Equals
85100
- !Ref EnableVersioning
86101
- 'true'
102+
UseAsStaticSite: !Equals
103+
- !Ref EnableStaticSite
104+
- 'true'
87105
Resources:
88106
S3bucket:
89107
Type: 'AWS::S3::Bucket'
90108
Properties:
91109
BucketName: !Ref BucketName
92110
AccessControl: !Ref BucketAccessControl
111+
WebsiteConfiguration: !If
112+
- UseAsStaticSite
113+
- IndexDocument: !Ref StaticSiteIndex
114+
ErrorDocument: !Ref StaticSiteError
115+
- !Ref 'AWS::NoValue'
93116
LifecycleConfiguration:
94117
Rules:
95118
- Id: GlacierRule
@@ -139,3 +162,8 @@ Outputs:
139162
- S3bucket
140163
- Arn
141164
Description: Name of the Amazon S3 bucket
165+
WebsiteURL:
166+
Value: !GetAtt
167+
- S3bucket
168+
- WebsiteURL
169+
Description: URL of the bucket that was created

examples/s3bucket.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ metadata:
44
name: s3bucket.aws-operator.com
55
spec:
66
versioning: true
7-
accessControl: Private
7+
accessControl: PublicRead
8+
website:
9+
enabled: true
10+
indexPage: index.html
11+
errorPage: 500.html
812
logging:
913
enabled: false
1014
prefix: "archive"

models/s3bucket.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ spec:
5959
Logging prefix to attach to all logs in the bucket.
6060
structKey: Prefix
6161
templateKey: LoggingPrefix
62+
- key: website
63+
type: object
64+
description: |
65+
Defines the options for creating a static website
66+
structKey: Website
67+
templateKey: Website
68+
properties:
69+
- key: enabled
70+
type: bool
71+
false: true
72+
description: |
73+
Website Enabled configures the S3 Bucket as a static site
74+
structKey: Enabled
75+
templateKey: EnableStaticSite
76+
- key: indexPage
77+
type: string
78+
default: "index.html"
79+
description: |
80+
Index document for the S3 bucket
81+
structKey: IndexPage
82+
templateKey: StaticSiteIndex
83+
- key: errorPage
84+
type: string
85+
default: "500.html"
86+
description: |
87+
Error document for the S3 bucket
88+
structKey: ErrorPage
89+
templateKey: StaticSiteError
6290
output:
6391
schema:
6492
type: object
@@ -75,6 +103,13 @@ spec:
75103
BucketARN is the full Amazon ARN for the bucket created
76104
structKey: BucketARN
77105
templateKey: BucketArn
106+
- key: websiteURL
107+
type: string
108+
description: |
109+
WebsiteURL is the DNS record for the static site
110+
structKey: WebsiteURL
111+
templateKey: WebsiteURL
112+
78113
additionalResources:
79114
services:
80115
- name: s3BucketSvc
@@ -95,4 +130,6 @@ spec:
95130
value: "{{.Config.Region}}"
96131
- key: bucketURL
97132
value: "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com"
133+
- key: websiteURL
134+
value: "{{.Obj.Output.WebsiteURL}}"
98135

0 commit comments

Comments
 (0)