# ViewerProtocolPolicy

How HTTPs should be handled with your distribution.

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

## Example

TypeScript:

```ts
// Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
declare const myBucket: s3.Bucket;
const myWebDistribution = new cloudfront.Distribution(this, 'myDist', {
  defaultBehavior: {
    origin: new origins.S3Origin(myBucket),
    allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
    viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
  },
});
```

Python:

```python
# Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
# my_bucket: s3.Bucket

my_web_distribution = cloudfront.Distribution(self, "myDist",
    default_behavior=cloudfront.BehaviorOptions(
        origin=origins.S3Origin(my_bucket),
        allowed_methods=cloudfront.AllowedMethods.ALLOW_ALL,
        viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS
    )
)
```

Java:

```java
// Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
Bucket myBucket;

Distribution myWebDistribution = Distribution.Builder.create(this, "myDist")
        .defaultBehavior(BehaviorOptions.builder()
                .origin(new S3Origin(myBucket))
                .allowedMethods(AllowedMethods.ALLOW_ALL)
                .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS)
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
Bucket myBucket;

var myWebDistribution = new Distribution(this, "myDist", new DistributionProps {
    DefaultBehavior = new BehaviorOptions {
        Origin = new S3Origin(myBucket),
        AllowedMethods = AllowedMethods.ALLOW_ALL,
        ViewerProtocolPolicy = ViewerProtocolPolicy.REDIRECT_TO_HTTPS
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
var myBucket Bucket

myWebDistribution := cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(myBucket),
		AllowedMethods: cloudfront.AllowedMethods_ALLOW_ALL(),
		ViewerProtocolPolicy: cloudfront.ViewerProtocolPolicy_REDIRECT_TO_HTTPS,
	},
})
```

## Members

| Member | Description |
| --- | --- |
| `HTTPS_ONLY` | HTTPS only. |
| `REDIRECT_TO_HTTPS` | Will redirect HTTP requests to HTTPS. |
| `ALLOW_ALL` | Both HTTP and HTTPS supported. |

## Referenced by

- [`AddBehaviorOptions`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.AddBehaviorOptions.html).viewerProtocolPolicy
- [`Behavior`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Behavior.html).viewerProtocolPolicy
- [`CloudFrontWebDistributionProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CloudFrontWebDistributionProps.html).viewerProtocolPolicy
