-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloudFrontWithFunction.json
More file actions
84 lines (84 loc) · 2.29 KB
/
CloudFrontWithFunction.json
File metadata and controls
84 lines (84 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "CloudFront Distribtion with Function used to add headers",
"Resources": {
"CloudFrontDistribution": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Aliases": [
"domain"
],
"DefaultCacheBehavior": {
"CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
"Compress": true,
"FunctionAssociations": [
{
"EventType": "viewer-response",
"FunctionARN": {
"Ref": "CloudFrontFunction"
}
}
],
"TargetOriginId": "S3 Static Site",
"ViewerProtocolPolicy": "redirect-to-https"
},
"Enabled": true,
"Origins": [
{
"DomainName": "bucket address",
"Id": "S3 Static Site",
"CustomOriginConfig": {
"OriginProtocolPolicy": "http-only"
}
}
],
"ViewerCertificate": {
"AcmCertificateArn": "cert",
"MinimumProtocolVersion": "TLSv1.2_2019",
"SslSupportMethod": "sni-only"
}
},
"Tags": [
{
"Key": "Test",
"Value": "True"
}
]
}
},
"CloudFrontFunction": {
"Type": "AWS::CloudFront::Function",
"Properties": {
"AutoPublish": true,
"FunctionCode": "function handler(event) {event.response.headers['x-hello'] = {value: 'wibble'};return event.response;}",
"Name": "Add-x-hello-header",
"FunctionConfig": {
"Comment": "Add-x-hello-header",
"Runtime": "cloudfront-js-1.0"
}
}
},
"DNS": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneId": "zone",
"RecordSets": [
{
"Name": "domain",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": {
"Fn::GetAtt": [
"CloudFrontDistribution",
"DomainName"
]
}
}
}
]
}
}
}
}