-
Notifications
You must be signed in to change notification settings - Fork 13
/
quickstart-aws-acm-certificate.template.yml
214 lines (214 loc) · 6.39 KB
/
quickstart-aws-acm-certificate.template.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
AWSTemplateFormatVersion: '2010-09-09'
Description: "(qs-1qu5sufei) Creates R53 records and ACM Certificate."
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: DNS Configuration
Parameters:
- DomainName
- HostedZoneID
- Label:
default: AWS Quick Start Configuration
Parameters:
- QSS3BucketName
- QSS3BucketRegion
- QSS3KeyPrefix
ParameterLabels:
QSS3KeyPrefix:
default: Quick Start S3 Key Prefix
QSS3BucketName:
default: Quick Start S3 Bucket Name
QSS3BucketRegion:
default: Quick Start S3 Bucket Region
DomainName:
default: Domain Name
HostedZoneID:
default: Route 53 Hosted Zone ID
Parameters:
# Quick Start Configuration
QSS3BucketName:
AllowedPattern: '^[0-9a-zA-Z]+([0-9a-zA-Z-]*[0-9a-zA-Z])*$'
ConstraintDescription:
Quick Start bucket name can include numbers, lowercase
letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen
(-).
Default: aws-quickstart
Description:
S3 bucket name for the Quick Start assets. Quick Start bucket name
can include numbers, lowercase letters, uppercase letters, and hyphens (-).
It cannot start or end with a hyphen (-).
Type: String
QSS3BucketRegion:
Default: 'us-east-1'
Description: 'The AWS Region where the Quick Start S3 bucket (QSS3BucketName) is hosted. When using your own bucket, you must specify this value.'
Type: String
QSS3KeyPrefix:
AllowedPattern: '^[0-9a-zA-Z-/]*$'
ConstraintDescription:
Quick Start key prefix can include numbers, lowercase letters,
uppercase letters, hyphens (-), and forward slash (/).
Default: quickstart-aws-acm-certificate/
Description:
S3 key prefix for the Quick Start assets. Quick Start key prefix
can include numbers, lowercase letters, uppercase letters, hyphens (-), and
forward slash (/).
Type: String
HostedZoneID:
Description: 'OPTIONAL: Route 53 Hosted Zone ID to use. If left blank, Route 53
will not be configured and DNS must be setup manually. If you specify this,
you must also specify DomainName'
Type: String
MaxLength: '32'
Default: ''
DomainName:
Description: 'OPTIONAL: Domain Name configured for the cluster. If left blank,
DNS must be configured manually, and an existing certificate must be used.'
Type: String
Default: ''
Conditions:
UsingDefaultBucket: !Equals [!Ref QSS3BucketName, 'aws-quickstart']
SetupRoute53:
Fn::And:
- Fn::Not:
- Fn::Equals:
- Ref: HostedZoneID
- ''
- Fn::Not:
- Fn::Equals:
- Ref: DomainName
- ''
UseEmailForACMValidation:
Fn::And:
- Fn::Equals:
- Ref: HostedZoneID
- ''
- Fn::Not:
- Fn::Equals:
- Ref: DomainName
- ''
IsSubmodule:
Fn::Not:
- Fn::Equals:
- Ref: QSS3KeyPrefix
- quickstart-aws-acm-certificate/
Resources:
# So we can copy the ACM lambda everywhere
CopyZips:
Metadata:
cfn-lint:
config:
ignore_checks:
- W9198
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL:
!Sub
- 'https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}submodules/lambda-copyzips/templates/copy-zips.template.yaml'
- S3Region: !If [UsingDefaultBucket, !Ref 'AWS::Region', !Ref QSS3BucketRegion]
S3Bucket: !If [UsingDefaultBucket, !Sub '${QSS3BucketName}-${AWS::Region}', !Ref QSS3BucketName]
Parameters:
QSS3BucketName: !Ref QSS3BucketName
QSS3BucketRegion: !Ref QSS3BucketRegion
QSS3KeyPrefix: !Ref QSS3KeyPrefix
SourceObjects: "functions/packages/ACMCert/lambda.zip"
ACMCertificateRole:
Condition: SetupRoute53
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Path: "/"
Policies:
- PolicyName: lambda-acm
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- acm:RequestCertificate
- acm:DescribeCertificate
- acm:DeleteCertificate
Resource:
- "*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- "*"
- Effect: Allow
Action:
- route53:ChangeResourceRecordSets
Resource:
- Fn::Sub: arn:${AWS::Partition}:route53:::hostedzone/${HostedZoneID}
- Effect: Allow
Action:
- logs:FilterLogEvents
Resource:
- "*"
ACMCertificateLambda:
Condition: SetupRoute53
Type: AWS::Lambda::Function
Properties:
Description: Creates and verifies an ACM certificate using DNS validation and
route53
Handler: lambda_function.handler
Runtime: python2.7
Role:
Fn::GetAtt:
- ACMCertificateRole
- Arn
Timeout: 900
Code:
S3Bucket: !GetAtt "CopyZips.Outputs.LambdaZipsBucket"
S3Key: !Sub "${QSS3KeyPrefix}functions/packages/ACMCert/lambda.zip"
ACMCertificateDNS:
Condition: SetupRoute53
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken:
Fn::GetAtt:
- ACMCertificateLambda
- Arn
HostedZoneId:
Ref: HostedZoneID
HostNames:
- Ref: DomainName
- Fn::Join:
- ''
- - "*."
- Ref: DomainName
ACMCertificateEmail:
Condition: UseEmailForACMValidation
Type: AWS::CertificateManager::Certificate
Properties:
DomainName:
Ref: DomainName
SubjectAlternativeNames:
- Fn::Join:
- ''
- - "*."
- Ref: DomainName
DomainValidationOptions:
- DomainName:
Ref: DomainName
ValidationDomain:
Ref: DomainName
Outputs:
ACMCertificate:
Description: ARN of the ACM-Generated SSL Certificate
Value:
Fn::If:
- SetupRoute53
- Fn::GetAtt:
- ACMCertificateDNS
- Arn
- Ref: ACMCertificateEmail