GeoRestriction Class
Controls the countries in which content is distributed.
Example
ts
// Adding restrictions to a Cloudfront Web Distribution.
declare const sourceBucket: s3.Bucket;
new cloudfront.CloudFrontWebDistribution(this, 'MyDistribution', {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: sourceBucket,
},
behaviors : [ {isDefaultBehavior: true}],
},
],
geoRestriction: cloudfront.GeoRestriction.allowlist('US', 'GB'),
});
python
# Adding restrictions to a Cloudfront Web Distribution.
# source_bucket: s3.Bucket
cloudfront.CloudFrontWebDistribution(self, "MyDistribution",
origin_configs=[cloudfront.SourceConfiguration(
s3_origin_source=cloudfront.S3OriginConfig(
s3_bucket_source=source_bucket
),
behaviors=[cloudfront.Behavior(is_default_behavior=True)]
)
],
geo_restriction=cloudfront.GeoRestriction.allowlist("US", "GB")
)
java
// Adding restrictions to a Cloudfront Web Distribution.
Bucket sourceBucket;
CloudFrontWebDistribution.Builder.create(this, "MyDistribution")
.originConfigs(List.of(SourceConfiguration.builder()
.s3OriginSource(S3OriginConfig.builder()
.s3BucketSource(sourceBucket)
.build())
.behaviors(List.of(Behavior.builder().isDefaultBehavior(true).build()))
.build()))
.geoRestriction(GeoRestriction.allowlist("US", "GB"))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Adding restrictions to a Cloudfront Web Distribution.
Bucket sourceBucket;
new CloudFrontWebDistribution(this, "MyDistribution", new CloudFrontWebDistributionProps {
OriginConfigs = new [] { new SourceConfiguration {
S3OriginSource = new S3OriginConfig {
S3BucketSource = sourceBucket
},
Behaviors = new [] { new Behavior { IsDefaultBehavior = true } }
} },
GeoRestriction = GeoRestriction.Allowlist("US", "GB")
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Adding restrictions to a Cloudfront Web Distribution.
var sourceBucket Bucket
cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyDistribution"), &CloudFrontWebDistributionProps{
OriginConfigs: []SourceConfiguration{
&SourceConfiguration{
S3OriginSource: &S3OriginConfig{
S3BucketSource: sourceBucket,
},
Behaviors: []Behavior{
&Behavior{
IsDefaultBehavior: jsii.Boolean(true),
},
},
},
},
GeoRestriction: cloudfront.GeoRestriction_Allowlist(jsii.String("US"), jsii.String("GB")),
})
Properties
locationsstring[]locationstyping.List[str]locationsList<String>Locationsstring[]Locations*[]*string#Two-letter, uppercase country code for a country that you want to allow/deny.
Include one element for each country. See ISO 3166-1-alpha-2 code on the International Organization for Standardization website
restrictionTypestringrestriction_typestrrestrictionTypeStringRestrictionTypestringRestrictionType*string#Specifies the restriction type to impose.
Methods
allowlist(...locations: string[]): GeoRestriction // chainable@staticmethod def allowlist(locations: str) -> GeoRestrictionpublic static GeoRestriction allowlist(String locations)public static GeoRestriction Allowlist(string locations)func Allowlist(Locations *string) GeoRestrictionstatic#Allow specific countries which you want CloudFront to distribute your content.
1 parameter
Parameters
locationslocationslocationslocationsLocations— Two-letter, uppercase country code for a country that you want to allow.
denylist(...locations: string[]): GeoRestriction // chainable@staticmethod def denylist(locations: str) -> GeoRestrictionpublic static GeoRestriction denylist(String locations)public static GeoRestriction Denylist(string locations)func Denylist(Locations *string) GeoRestrictionstatic#Deny specific countries which you don't want CloudFront to distribute your content.
1 parameter
Parameters
locationslocationslocationslocationsLocations— Two-letter, uppercase country code for a country that you want to deny.