|
229 | 229 | assets_custom_domain_condition = "AssetsCloudFrontDomainCondition"
|
230 | 230 | template.add_condition(assets_custom_domain_condition, Not(Equals(Ref(assets_cloudfront_domain), "")))
|
231 | 231 |
|
| 232 | + assets_certificate_arn = template.add_parameter( |
| 233 | + Parameter( |
| 234 | + "AssetsCloudFrontCertArn", |
| 235 | + Description="If (1) you specified a custom static media domain, (2) your stack is NOT in the us-east-1 " |
| 236 | + "region, and (3) you wish to serve static media over HTTPS, you must manually create an " |
| 237 | + "ACM certificate in the us-east-1 region and provide its ARN here.", |
| 238 | + Type="String", |
| 239 | + ), |
| 240 | + group="Static Media", |
| 241 | + label="CloudFront SSL Certificate ARN", |
| 242 | + ) |
| 243 | + assets_certificate_arn_condition = "AssetsCloudFrontCertArnCondition" |
| 244 | + template.add_condition(assets_certificate_arn_condition, Not(Equals(Ref(assets_certificate_arn), ""))) |
| 245 | + |
232 | 246 | # Currently, you can specify only certificates that are in the US East (N. Virginia) region.
|
233 | 247 | # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distributionconfig-viewercertificate.html
|
234 |
| - assets_custom_domain_and_us_east_1_condition = "AssetsCloudFrontDomainAndUsEast1Condition" |
| 248 | + assets_create_certificate_condition = "AssetsCreateCertificateCondition" |
235 | 249 | template.add_condition(
|
236 |
| - assets_custom_domain_and_us_east_1_condition, |
237 |
| - And(Not(Equals(Ref(assets_cloudfront_domain), "")), Equals(Ref(AWS_REGION), "us-east-1")) |
| 250 | + assets_create_certificate_condition, |
| 251 | + And( |
| 252 | + Not(Equals(Ref(assets_cloudfront_domain), "")), |
| 253 | + Equals(Ref(AWS_REGION), "us-east-1"), |
| 254 | + Equals(Ref(assets_certificate_arn), "") |
| 255 | + ) |
238 | 256 | )
|
239 | 257 |
|
240 | 258 | assets_certificate = template.add_resource(
|
241 | 259 | Certificate(
|
242 | 260 | 'AssetsCertificate',
|
243 |
| - Condition=assets_custom_domain_and_us_east_1_condition, |
| 261 | + Condition=assets_create_certificate_condition, |
244 | 262 | DomainName=Ref(assets_cloudfront_domain),
|
245 | 263 | DomainValidationOptions=[
|
246 | 264 | DomainValidationOption(
|
|
251 | 269 | )
|
252 | 270 | )
|
253 | 271 |
|
254 |
| - assets_certificate_arn = template.add_parameter( |
255 |
| - Parameter( |
256 |
| - "AssetsCloudFrontCertArn", |
257 |
| - Description="If (1) you specified a custom static media domain, (2) your stack is NOT in the us-east-1 " |
258 |
| - "region, and (3) you wish to serve static media over HTTPS, you must manually create an " |
259 |
| - "ACM certificate in the us-east-1 region and provide its ARN here.", |
260 |
| - Type="String", |
261 |
| - ), |
262 |
| - group="Static Media", |
263 |
| - label="CloudFront SSL Certificate ARN", |
264 |
| - ) |
265 |
| - assets_certificate_arn_condition = "AssetsCloudFrontCertArnCondition" |
266 |
| - template.add_condition(assets_certificate_arn_condition, Not(Equals(Ref(assets_certificate_arn), ""))) |
267 |
| - |
268 | 272 | # Create a CloudFront CDN distribution
|
269 | 273 | distribution = template.add_resource(
|
270 | 274 | Distribution(
|
|
275 | 279 | # use the ACM certificate we created (if any), otherwise fall back to the manually-supplied
|
276 | 280 | # ARN (if any)
|
277 | 281 | ViewerCertificate=If(
|
278 |
| - assets_custom_domain_and_us_east_1_condition, |
| 282 | + assets_create_certificate_condition, |
279 | 283 | ViewerCertificate(
|
280 | 284 | AcmCertificateArn=Ref(assets_certificate),
|
281 | 285 | SslSupportMethod='sni-only',
|
|
0 commit comments