Repository: cloudtools/troposphere

Issue:
S3Origin doesn't have a DomainName property
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-s3originconfig.html doesn't list the `DomainName` property, but it was added as mandatory by #1235 , introducing a regression.


Discussion:

Resolving patch:
diff --git a/examples/CloudFront_S3.py b/examples/CloudFront_Distribution_S3.py
similarity index 93%
rename from examples/CloudFront_S3.py
rename to examples/CloudFront_Distribution_S3.py
--- a/examples/CloudFront_S3.py
+++ b/examples/CloudFront_Distribution_S3.py
@@ -6,7 +6,7 @@
 from troposphere.cloudfront import Distribution, DistributionConfig
 from troposphere.cloudfront import Origin, DefaultCacheBehavior
 from troposphere.cloudfront import ForwardedValues
-from troposphere.cloudfront import S3Origin
+from troposphere.cloudfront import S3OriginConfig
 
 
 t = Template()
@@ -30,7 +30,7 @@
     "myDistribution",
     DistributionConfig=DistributionConfig(
         Origins=[Origin(Id="Origin 1", DomainName=Ref(s3dnsname),
-                        S3OriginConfig=S3Origin(DomainName=Ref(s3dnsname)))],
+                        S3OriginConfig=S3OriginConfig())],
         DefaultCacheBehavior=DefaultCacheBehavior(
             TargetOriginId="Origin 1",
             ForwardedValues=ForwardedValues(
diff --git a/examples/CloudFront_StreamingDistribution_S3.py b/examples/CloudFront_StreamingDistribution_S3.py
new file mode 100644
--- /dev/null
+++ b/examples/CloudFront_StreamingDistribution_S3.py
@@ -0,0 +1,48 @@
+# Converted from CloudFront_S3.template located at:
+# http://aws.amazon.com/cloudformation/aws-cloudformation-templates/
+
+from troposphere import GetAtt, Join, Output
+from troposphere import Parameter, Ref, Template
+from troposphere.cloudfront import StreamingDistribution
+from troposphere.cloudfront import StreamingDistributionConfig
+from troposphere.cloudfront import S3Origin
+from troposphere.cloudfront import TrustedSigners
+
+
+t = Template()
+
+t.add_description(
+    "AWS CloudFormation Sample Template CloudFront_S3: Sample template "
+    "showing how to create an Amazon CloudFront Streaming distribution "
+    "using an S3 origin. "
+    "**WARNING** This template creates a CloudFront distribution. "
+    "You will be billed for the AWS resources used if you create "
+    "a stack from this template.")
+
+s3dnsname = t.add_parameter(Parameter(
+    "S3DNSName",
+    Description="The DNS name of an existing S3 bucket to use as the "
+                "Cloudfront distribution origin",
+    Type="String",
+))
+
+myDistribution = t.add_resource(StreamingDistribution(
+    "myDistribution",
+    StreamingDistributionConfig=StreamingDistributionConfig(
+        Comment="Streaming distribution",
+        Enabled=True,
+        S3Origin=S3Origin(DomainName=Ref(s3dnsname)),
+        TrustedSigners=TrustedSigners(
+            Enabled=False,
+        ),
+    )
+))
+
+t.add_output([
+    Output("DistributionId", Value=Ref(myDistribution)),
+    Output(
+        "DistributionName",
+        Value=Join("", ["http://", GetAtt(myDistribution, "DomainName")])),
+])
+
+print(t.to_json())
diff --git a/troposphere/cloudfront.py b/troposphere/cloudfront.py
--- a/troposphere/cloudfront.py
+++ b/troposphere/cloudfront.py
@@ -96,6 +96,12 @@ class OriginCustomHeader(AWSProperty):
     }
 
 
+class S3OriginConfig(AWSProperty):
+    props = {
+        'OriginAccessIdentity': (basestring, False),
+    }
+
+
 class Origin(AWSProperty):
     props = {
         'CustomOriginConfig': (CustomOriginConfig, False),
@@ -103,7 +109,7 @@ class Origin(AWSProperty):
         'Id': (basestring, True),
         'OriginCustomHeaders': ([OriginCustomHeader], False),
         'OriginPath': (basestring, False),
-        'S3OriginConfig': (S3Origin, False),
+        'S3OriginConfig': (S3OriginConfig, False),
 
     }
 


Test patch:
diff --git a/tests/examples_output/CloudFront_S3.template b/tests/examples_output/CloudFront_Distribution_S3.template
similarity index 90%
rename from tests/examples_output/CloudFront_S3.template
rename to tests/examples_output/CloudFront_Distribution_S3.template
--- a/tests/examples_output/CloudFront_S3.template
+++ b/tests/examples_output/CloudFront_Distribution_S3.template
@@ -48,11 +48,7 @@
                                 "Ref": "S3DNSName"
                             },
                             "Id": "Origin 1",
-                            "S3OriginConfig": {
-                                "DomainName": {
-                                    "Ref": "S3DNSName"
-                                }
-                            }
+                            "S3OriginConfig": {}
                         }
                     ]
                 }
diff --git a/tests/examples_output/CloudFront_StreamingDistribution_S3.template b/tests/examples_output/CloudFront_StreamingDistribution_S3.template
new file mode 100644
--- /dev/null
+++ b/tests/examples_output/CloudFront_StreamingDistribution_S3.template
@@ -0,0 +1,51 @@
+{
+    "Description": "AWS CloudFormation Sample Template CloudFront_S3: Sample template showing how to create an Amazon CloudFront Streaming distribution using an S3 origin. **WARNING** This template creates a CloudFront distribution. You will be billed for the AWS resources used if you create a stack from this template.",
+    "Outputs": {
+        "DistributionId": {
+            "Value": {
+                "Ref": "myDistribution"
+            }
+        },
+        "DistributionName": {
+            "Value": {
+                "Fn::Join": [
+                    "",
+                    [
+                        "http://",
+                        {
+                            "Fn::GetAtt": [
+                                "myDistribution",
+                                "DomainName"
+                            ]
+                        }
+                    ]
+                ]
+            }
+        }
+    },
+    "Parameters": {
+        "S3DNSName": {
+            "Description": "The DNS name of an existing S3 bucket to use as the Cloudfront distribution origin",
+            "Type": "String"
+        }
+    },
+    "Resources": {
+        "myDistribution": {
+            "Properties": {
+                "StreamingDistributionConfig": {
+                    "Comment": "Streaming distribution",
+                    "Enabled": "true",
+                    "S3Origin": {
+                        "DomainName": {
+                            "Ref": "S3DNSName"
+                        }
+                    },
+                    "TrustedSigners": {
+                        "Enabled": "false"
+                    }
+                }
+            },
+            "Type": "AWS::CloudFront::StreamingDistribution"
+        }
+    }
+}