forked from bertrandom/HTML5-Zombocom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
139 lines (128 loc) · 3.76 KB
/
serverless.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Welcome to serverless. Read the docs
# https://serverless.com/framework/docs/
service: serverless-zombocom
plugins:
- serverless-sync-s3buckets
custom:
syncS3Buckets:
- bucketRef: StaticSite
localDir: static
hostedZoneName: serverless-zombo.com
hostedZoneId: Z2FDTNDATAQYW2 # CloudFront
aliasDNSName: s3-website-us-east-1.amazonaws.com
provider:
name: aws
runtime: nodejs6.10
stage: prod
stackTags:
serverless:servess: ${self:service}
resources:
Resources:
## Specifying the S3 Bucket
StaticSite:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
StaticSiteS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: StaticSite
PolicyDocument:
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource:
Fn::Join: [
"", [
"arn:aws:s3:::",
{
"Ref": "StaticSite"
},
"/*"
]
]
StaticSiteCert:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: ${self:custom.hostedZoneName}
DomainValidationOptions:
- DomainName: ${self:custom.hostedZoneName}
ValidationDomain: ${self:custom.hostedZoneName}
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:
Fn::Join: [
"", [
{ "Ref": "StaticSite" },
".s3.amazonaws.com"
]
]
# It isn't necessary to sue this value; but we need the same
# value for DefaultCacheBehavior.TargetOriginId
Id:
Ref: StaticSite
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Enabled: 'true'
Aliases:
- ${self:custom.hostedZoneName}
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
TargetOriginId:
Ref: StaticSite
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
AcmCertificateArn:
Ref: StaticSiteCert
SslSupportMethod: sni-only
## Uncomment the following section in case you want to enable logging for CloudFront requests
# Logging:
# IncludeCookies: 'false'
# Bucket: mylogs.s3.amazonaws.com
# Prefix: myprefix
DependsOn:
- StaticSiteS3BucketPolicy
DnsRecord:
Type: "AWS::Route53::RecordSet"
Properties:
AliasTarget:
DNSName:
Fn::GetAtt:
- CloudFrontDistribution
- DomainName
HostedZoneId: ${self:custom.hostedZoneId}
HostedZoneName: ${self:custom.hostedZoneName}.
Name: ${self:custom.hostedZoneName}.
Type: 'A'
Outputs:
StaticSiteS3BucketName:
Value:
Ref: StaticSite
CloudFrontDistribution:
Value:
Fn::GetAtt:
- CloudFrontDistribution
- DomainName