-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-distribution.sh
More file actions
executable file
·75 lines (69 loc) · 2 KB
/
update-distribution.sh
File metadata and controls
executable file
·75 lines (69 loc) · 2 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
#!/bin/bash
source cloudfront-info.env
# Get current distribution config
aws cloudfront get-distribution-config --id $DISTRIBUTION_ID --query 'DistributionConfig' > temp-config.json
# Create updated config with custom domain and SSL
cat > updated-config.json << EOF
{
"CallerReference": "ccai-collections-cf-1754517629",
"Aliases": {
"Quantity": 1,
"Items": ["collections.cloudcontactai.com"]
},
"DefaultRootObject": "index.html",
"Comment": "CCAI Collections CloudFront Distribution with SSL",
"Enabled": true,
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "ccai-collections-s3-origin",
"DomainName": "ccai-collections-1754517629.s3-website-us-east-1.amazonaws.com",
"CustomOriginConfig": {
"HTTPPort": 80,
"HTTPSPort": 443,
"OriginProtocolPolicy": "http-only"
}
}
]
},
"DefaultCacheBehavior": {
"TargetOriginId": "ccai-collections-s3-origin",
"ViewerProtocolPolicy": "redirect-to-https",
"MinTTL": 0,
"ForwardedValues": {
"QueryString": false,
"Cookies": {
"Forward": "none"
}
},
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
}
},
"CustomErrorResponses": {
"Quantity": 1,
"Items": [
{
"ErrorCode": 404,
"ResponsePagePath": "/index.html",
"ResponseCode": "200",
"ErrorCachingMinTTL": 300
}
]
},
"ViewerCertificate": {
"ACMCertificateArn": "$CERT_ARN",
"SSLSupportMethod": "sni-only",
"MinimumProtocolVersion": "TLSv1.2_2021"
},
"PriceClass": "PriceClass_100"
}
EOF
# Get ETag for update
ETAG=$(aws cloudfront get-distribution --id $DISTRIBUTION_ID --query 'ETag' --output text)
echo "Updating CloudFront distribution with custom domain..."
aws cloudfront update-distribution --id $DISTRIBUTION_ID --distribution-config file://updated-config.json --if-match $ETAG
echo "Distribution updated. Create CNAME record:"
echo "collections.cloudcontactai.com -> $CLOUDFRONT_DOMAIN"