# GeoRestriction

Controls the countries in which content is distributed.

Obtainable from: GeoRestriction.allowlist, GeoRestriction.denylist

- Source: [`aws-cloudfront/lib/geo-restriction.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cloudfront/lib/geo-restriction.ts#L7)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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")
});
```

Golang:

```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

- `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

- `restrictionType`: string — Specifies the restriction type to impose.

## Methods

- `allowlist(...locations: string[]): GeoRestriction // chainable` (static) — Allow specific countries which you want CloudFront to distribute your content.

  **Parameters**

  - `locations` — Two-letter, uppercase country code for a country that you want to allow.

- `denylist(...locations: string[]): GeoRestriction // chainable` (static) — Deny specific countries which you don't want CloudFront to distribute your content.

  **Parameters**

  - `locations` — Two-letter, uppercase country code for a country that you want to deny.
