@@ -695,6 +695,31 @@ export interface CorsRule {
695
695
readonly exposedHeaders ?: string [ ] ;
696
696
}
697
697
698
+ /**
699
+ * All http request methods
700
+ */
701
+ export enum RedirectProtocol {
702
+ HTTP = 'http' ,
703
+ HTTPS = 'https' ,
704
+ }
705
+
706
+ /**
707
+ * Specifies a redirect behavior of all requests to a website endpoint of a bucket.
708
+ */
709
+ export interface RedirectTarget {
710
+ /**
711
+ * Name of the host where requests are redirected
712
+ */
713
+ readonly hostName : string ;
714
+
715
+ /**
716
+ * Protocol to use when redirecting requests
717
+ *
718
+ * @default - The protocol used in the original request.
719
+ */
720
+ readonly protocol ?: RedirectProtocol ;
721
+ }
722
+
698
723
export interface BucketProps {
699
724
/**
700
725
* The kind of server-side encryption to apply to this bucket.
@@ -762,6 +787,15 @@ export interface BucketProps {
762
787
*/
763
788
readonly websiteErrorDocument ?: string ;
764
789
790
+ /**
791
+ * Specifies the redirect behavior of all requests to a website endpoint of a bucket.
792
+ *
793
+ * If you specify this property, you can't specify "websiteIndexDocument" nor "websiteErrorDocument".
794
+ *
795
+ * @default - No redirection.
796
+ */
797
+ readonly websiteRedirect ?: RedirectTarget ;
798
+
765
799
/**
766
800
* Grants public read access to all objects in the bucket.
767
801
* Similar to calling `bucket.grantPublicAccess()`
@@ -1214,17 +1248,22 @@ export class Bucket extends BucketBase {
1214
1248
}
1215
1249
1216
1250
private renderWebsiteConfiguration ( props : BucketProps ) : CfnBucket . WebsiteConfigurationProperty | undefined {
1217
- if ( ! props . websiteErrorDocument && ! props . websiteIndexDocument ) {
1251
+ if ( ! props . websiteErrorDocument && ! props . websiteIndexDocument && ! props . websiteRedirect ) {
1218
1252
return undefined ;
1219
1253
}
1220
1254
1221
1255
if ( props . websiteErrorDocument && ! props . websiteIndexDocument ) {
1222
1256
throw new Error ( `"websiteIndexDocument" is required if "websiteErrorDocument" is set` ) ;
1223
1257
}
1224
1258
1259
+ if ( props . websiteRedirect && ( props . websiteErrorDocument || props . websiteIndexDocument ) ) {
1260
+ throw new Error ( '"websiteIndexDocument" and "websiteErrorDocument" cannot be set if "websiteRedirect" is used' ) ;
1261
+ }
1262
+
1225
1263
return {
1226
1264
indexDocument : props . websiteIndexDocument ,
1227
- errorDocument : props . websiteErrorDocument
1265
+ errorDocument : props . websiteErrorDocument ,
1266
+ redirectAllRequestsTo : props . websiteRedirect ,
1228
1267
} ;
1229
1268
}
1230
1269
}
0 commit comments