Resource: awsS3BucketWebsiteConfiguration
Provides an S3 bucket website configuration resource. For more information, see Hosting Websites on S3.
Example Usage
With routingRule
configured
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.s3BucketWebsiteConfiguration.S3BucketWebsiteConfiguration(
this,
"example",
{
bucket: "${aws_s3_bucket.example.id}",
errorDocument: {
key: "error.html",
},
indexDocument: {
suffix: "index.html",
},
routingRule: [
{
condition: {
keyPrefixEquals: "docs/",
},
redirect: {
replaceKeyPrefixWith: "documents/",
},
},
],
}
);
With routingRules
configured
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.s3BucketWebsiteConfiguration.S3BucketWebsiteConfiguration(
this,
"example",
{
bucket: "${aws_s3_bucket.example.id}",
errorDocument: {
key: "error.html",
},
indexDocument: {
suffix: "index.html",
},
routingRules:
'[{\n "Condition": {\n "KeyPrefixEquals": "docs/"\n },\n "Redirect": {\n "ReplaceKeyPrefixWith": ""\n }\n}]\n',
}
);
Argument Reference
The following arguments are supported:
bucket
- (Required, Forces new resource) Name of the bucket.errorDocument
- (Optional, Conflicts withredirectAllRequestsTo
) Name of the error document for the website. See below.expectedBucketOwner
- (Optional, Forces new resource) Account ID of the expected bucket owner.indexDocument
- (Optional, Required ifredirectAllRequestsTo
is not specified) Name of the index document for the website. See below.redirectAllRequestsTo
- (Optional, Required ifindexDocument
is not specified) Redirect behavior for every request to this bucket's website endpoint. See below. Conflicts witherrorDocument
,indexDocument
, androutingRule
.routingRule
- (Optional, Conflicts withredirectAllRequestsTo
androutingRules
) List of rules that define when a redirect is applied and the redirect behavior. See below.routingRules
- (Optional, Conflicts withroutingRule
andredirectAllRequestsTo
) JSON array containing routing rules describing redirect behavior and when redirects are applied. Use this parameter when your routing rules contain empty String values (""
) as seen in the example above.
errorDocument
The errorDocument
configuration block supports the following arguments:
key
- (Required) Object key name to use when a 4XX class error occurs.
indexDocument
The indexDocument
configuration block supports the following arguments:
suffix
- (Required) Suffix that is appended to a request that is for a directory on the website endpoint. For example, if the suffix isindexHtml
and you make a request tosamplebucket/images/
, the data that is returned will be for the object with the key nameimages/indexHtml
. The suffix must not be empty and must not include a slash character.
redirectAllRequestsTo
The redirectAllRequestsTo
configuration block supports the following arguments:
hostName
- (Required) Name of the host where requests are redirected.protocol
- (Optional) Protocol to use when redirecting requests. The default is the protocol that is used in the original request. Valid values:http
,https
.
routingRule
The routingRule
configuration block supports the following arguments:
condition
- (Optional) Configuration block for describing a condition that must be met for the specified redirect to apply. See below.redirect
- (Required) Configuration block for redirect information. See below.
condition
The condition
configuration block supports the following arguments:
httpErrorCodeReturnedEquals
- (Optional, Required ifkeyPrefixEquals
is not specified) HTTP error code when the redirect is applied. If specified withkeyPrefixEquals
, then both must be true for the redirect to be applied.keyPrefixEquals
- (Optional, Required ifhttpErrorCodeReturnedEquals
is not specified) Object key name prefix when the redirect is applied. If specified withhttpErrorCodeReturnedEquals
, then both must be true for the redirect to be applied.
redirect
The redirect
configuration block supports the following arguments:
hostName
- (Optional) Host name to use in the redirect request.httpRedirectCode
- (Optional) HTTP redirect code to use on the response.protocol
- (Optional) Protocol to use when redirecting requests. The default is the protocol that is used in the original request. Valid values:http
,https
.replaceKeyPrefixWith
- (Optional, Conflicts withreplaceKeyWith
) Object key prefix to use in the redirect request. For example, to redirect requests for all pages with prefixdocs/
(objects in thedocs/
folder) todocuments/
, you can set acondition
block withkeyPrefixEquals
set todocs/
and in theredirect
setreplaceKeyPrefixWith
to/documents
.replaceKeyWith
- (Optional, Conflicts withreplaceKeyPrefixWith
) Specific object key to use in the redirect request. For example, redirect request toerrorHtml
.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
id
- Thebucket
orbucket
andexpectedBucketOwner
separated by a comma (,
) if the latter is provided.websiteDomain
- Domain of the website endpoint. This is used to create Route 53 alias records.websiteEndpoint
- Website endpoint.
Import
S3 bucket website configuration can be imported in one of two ways.
If the owner (account ID) of the source bucket is the same account used to configure the Terraform AWS Provider, the S3 bucket website configuration resource should be imported using the bucket
e.g.,
If the owner (account ID) of the source bucket differs from the account used to configure the Terraform AWS Provider, the S3 bucket website configuration resource should be imported using the bucket
and expectedBucketOwner
separated by a comma (,
) e.g.,