CloudFront - Add default timeouts for CustomOrigins (#6508)

This commit is contained in:
Bert Blommers 2023-07-11 09:31:07 +00:00 committed by GitHub
parent 7d31fe378d
commit 971568f226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View File

@ -101,9 +101,9 @@ class CustomOriginConfig:
def __init__(self, config: Dict[str, Any]):
self.http_port = config.get("HTTPPort")
self.https_port = config.get("HTTPSPort")
self.keep_alive = config.get("OriginKeepaliveTimeout")
self.keep_alive = config.get("OriginKeepaliveTimeout") or 5
self.protocol_policy = config.get("OriginProtocolPolicy")
self.read_timeout = config.get("OriginReadTimeout")
self.read_timeout = config.get("OriginReadTimeout") or 30
self.ssl_protocols = (
config.get("OriginSslProtocols", {}).get("Items", {}).get("SslProtocol")
or []

View File

@ -50,9 +50,9 @@ def example_dist_custom_config(ref):
"CustomOriginConfig": {
"HTTPPort": 80,
"HTTPSPort": 443,
"OriginKeepaliveTimeout": 5,
"OriginKeepaliveTimeout": 10,
"OriginProtocolPolicy": "http-only",
"OriginReadTimeout": 30,
"OriginReadTimeout": 15,
"OriginSslProtocols": {
"Quantity": 2,
"Items": ["TLSv1", "SSLv3"],
@ -70,3 +70,38 @@ def example_dist_custom_config(ref):
"Comment": "an optional comment that's not actually optional",
"Enabled": False,
}
def minimal_dist_custom_config(ref: str):
return {
"CallerReference": ref,
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "my-origin",
"DomainName": "example.com",
"CustomOriginConfig": {
"HTTPPort": 80,
"HTTPSPort": 443,
"OriginProtocolPolicy": "http-only",
},
}
],
},
"DefaultCacheBehavior": {
"TargetOriginId": "my-origin",
"ViewerProtocolPolicy": "redirect-to-https",
"DefaultTTL": 86400,
"AllowedMethods": {"Quantity": 2, "Items": ["GET", "HEAD"]},
"ForwardedValues": {
"QueryString": False,
"Cookies": {"Forward": "none"},
"Headers": {"Quantity": 0},
},
"TrustedSigners": {"Enabled": False, "Quantity": 0},
"MinTTL": 0,
},
"Comment": "My CloudFront distribution",
"Enabled": True,
}

View File

@ -446,6 +446,8 @@ def test_create_distribution_custom_config():
assert custom_config["HTTPPort"] == 80
assert custom_config["HTTPSPort"] == 443
assert custom_config["OriginReadTimeout"] == 15
assert custom_config["OriginKeepaliveTimeout"] == 10
assert custom_config["OriginProtocolPolicy"] == "http-only"
assert custom_config["OriginSslProtocols"] == {
"Items": ["TLSv1", "SSLv3"],
@ -453,6 +455,28 @@ def test_create_distribution_custom_config():
}
@mock_cloudfront
def test_create_distribution_minimal_custom_config():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.minimal_dist_custom_config("ref")
dist = client.create_distribution(DistributionConfig=config)["Distribution"]
dist_config = dist["DistributionConfig"]
assert len(dist_config["Origins"]["Items"]) == 1
custom_config = dist_config["Origins"]["Items"][0]["CustomOriginConfig"]
assert custom_config["HTTPPort"] == 80
assert custom_config["HTTPSPort"] == 443
assert custom_config["OriginReadTimeout"] == 30
assert custom_config["OriginKeepaliveTimeout"] == 5
assert custom_config["OriginProtocolPolicy"] == "http-only"
dist = client.get_distribution(Id=dist["Id"])["Distribution"]
dist_config = dist["DistributionConfig"]
get_custom_config = dist_config["Origins"]["Items"][0]["CustomOriginConfig"]
assert custom_config == get_custom_config
@mock_cloudfront
def test_list_distributions_without_any():
client = boto3.client("cloudfront", region_name="us-east-1")