Skip to content

Commit 851b236

Browse files
authored
Use AWS::ACM::Certificate (#44)
* Use AWS::ACM::Certificate * Update README
1 parent bf843ff commit 851b236

File tree

5 files changed

+15
-147
lines changed

5 files changed

+15
-147
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ To deploy the solution, you use [AWS CloudFormation](https://aws.amazon.com/clou
7272

7373
- **SubDomain:** The subdomain for your registered domain name. Viewers use the subdomain to access your website, for example: www.example.com. We recommend using the default value of **www** as the subdomain.
7474
- **DomainName:** Your registered domain name, such as example.com. This domain must be pointed to a Route 53 hosted zone.
75+
- **HostedZoneId** The Route 53 Hosted Zone Id containing the domain being used.
7576
- **CreateApex:** Optionally create an Alias to the domain apex (example.com) in your CloudFront configuration. Default is [no]
7677

7778
After entering values, choose the **Next** button.
@@ -138,7 +139,7 @@ https://s3.amazonaws.com/solution-builders-us-east-1/amazon-cloudfront-secure-st
138139
--stack-name <your CloudFormation stack name> \
139140
--template-file packaged.template \
140141
--capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
141-
--parameter-overrides DomainName=<your domain name> SubDomain=<your website subdomain>
142+
--parameter-overrides DomainName=<your domain name> SubDomain=<your website subdomain> HostedZoneId=<hosted zone id>
142143
```
143144

144145
8. [Optional] Run the following command to deploy the packaged CloudFormation template to a CloudFormation stack with a domain apex.
@@ -148,7 +149,7 @@ https://s3.amazonaws.com/solution-builders-us-east-1/amazon-cloudfront-secure-st
148149
--stack-name <your CloudFormation stack name> \
149150
--template-file packaged.template \
150151
--capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
151-
--parameter-overrides DomainName=<your domain name> SubDomain=<your website subdomain> CreateApex=yes
152+
--parameter-overrides DomainName=<your domain name> SubDomain=<your website subdomain> HostedZoneId=<hosted zone id> CreateApex=yes
152153
```
153154

154155

templates/acm-certificate.yaml

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,34 @@ Description: ACFS3 - Certificate creation
44
Parameters:
55
DomainName:
66
Type: String
7-
Region:
8-
Type: String
9-
Default: 'us-east-1'
10-
CFNCustomProvider:
11-
Type: String
12-
CopyFunction:
13-
Type: String
147
SubDomain:
158
Type: String
169
CreateApex:
1710
Type: String
11+
HostedZoneId:
12+
Type: String
1813

1914
Conditions:
2015
CreateApexConfig: !Equals
2116
- !Ref CreateApex
2217
- 'yes'
2318

2419
Resources:
25-
CopyCustomResource:
26-
Type: "AWS::CloudFormation::CustomResource"
27-
Properties:
28-
ServiceToken: !Ref CopyFunction
29-
3020
Certificate:
31-
Type: Custom::Certificate
32-
Properties:
21+
Type: AWS::CertificateManager::Certificate
22+
Properties:
3323
DomainName: !Sub '${SubDomain}.${DomainName}'
3424
SubjectAlternativeNames:
3525
Fn::If:
3626
- CreateApexConfig
3727
- - Ref: DomainName
3828
- Ref: AWS::NoValue
39-
Region: !Ref Region
29+
DomainValidationOptions:
30+
- DomainName: !Sub '${SubDomain}.${DomainName}'
31+
HostedZoneId: !Ref HostedZoneId
4032
ValidationMethod: DNS
41-
ServiceToken: !Ref 'CFNCustomProvider'
42-
43-
IssuedCertificate:
44-
Type: Custom::IssuedCertificate
45-
Properties:
46-
CertificateArn: !Ref Certificate
47-
ServiceToken: !Ref 'CFNCustomProvider'
48-
49-
CertificateDNSRecord:
50-
Type: Custom::CertificateDNSRecord
51-
Properties:
52-
CertificateArn: !Ref Certificate
53-
DomainName: !Sub '${SubDomain}.${DomainName}'
54-
ServiceToken: !Ref 'CFNCustomProvider'
55-
56-
apexCertificateDNSRecord:
57-
Type: Custom::CertificateDNSRecord
58-
Condition: CreateApexConfig
59-
Properties:
60-
CertificateArn: !Ref Certificate
61-
DomainName: !Ref DomainName
62-
ServiceToken: !Ref 'CFNCustomProvider'
63-
64-
DomainValidationRecord:
65-
Type: AWS::Route53::RecordSetGroup
66-
Properties:
67-
HostedZoneName: !Sub '${DomainName}.'
68-
RecordSets:
69-
- Name: !GetAtt CertificateDNSRecord.Name
70-
Type: !GetAtt CertificateDNSRecord.Type
71-
TTL: 60
72-
Weight: 1
73-
SetIdentifier: !Ref Certificate
74-
ResourceRecords:
75-
- !GetAtt CertificateDNSRecord.Value
76-
77-
apexDomainValidationRecord:
78-
Type: AWS::Route53::RecordSetGroup
79-
Condition: CreateApexConfig
80-
Properties:
81-
HostedZoneName: !Sub '${DomainName}.'
82-
RecordSets:
83-
- Name: !GetAtt apexCertificateDNSRecord.Name
84-
Type: !GetAtt apexCertificateDNSRecord.Type
85-
TTL: 60
86-
Weight: 1
87-
SetIdentifier: !Ref Certificate
88-
ResourceRecords:
89-
- !GetAtt apexCertificateDNSRecord.Value
9033

9134
Outputs:
92-
DNSRecord:
93-
Description: DNS record
94-
Value: !Sub '${CertificateDNSRecord.Name} ${CertificateDNSRecord.Type} ${CertificateDNSRecord.Value}'
95-
9635
CertificateArn:
9736
Description: Issued certificate
9837
Value: !Ref Certificate

templates/cloudfront-site.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ Resources:
135135
Type: AWS::CloudFront::ResponseHeadersPolicy
136136
Properties:
137137
ResponseHeadersPolicyConfig:
138-
Comment: "practera-security-headers-for-${env:APPV2S3BUCKET}"
139-
Name: "practera-security-headers-for-GlobalAPPv2"
138+
Name: !Sub "${AWS::StackName}-static-site-security-headers"
140139
SecurityHeadersConfig:
141140
StrictTransportSecurity:
142141
AccessControlMaxAgeSec: 63072000

templates/custom-resource.yaml

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,6 @@ Description: ACFS3 - Cert Provider with DNS validation
33
Transform: AWS::Serverless-2016-10-31
44

55
Resources:
6-
LambdaPermission:
7-
Type: AWS::Lambda::Permission
8-
Properties:
9-
Action: lambda:InvokeFunction
10-
FunctionName: !GetAtt CFNCustomProvider.Arn
11-
Principal: !GetAtt LambdaRole.Arn
12-
13-
LambdaPolicy:
14-
Type: AWS::IAM::Policy
15-
DependsOn:
16-
- LambdaRole
17-
Properties:
18-
PolicyName: CFNCertificateDomainResourceRecordProvider
19-
PolicyDocument:
20-
Version: '2012-10-17'
21-
Statement:
22-
- Effect: Allow
23-
Action:
24-
- acm:RequestCertificate
25-
- acm:DescribeCertificate
26-
- acm:UpdateCertificateOptions
27-
- acm:DeleteCertificate
28-
Resource:
29-
- '*'
30-
- Effect: Allow
31-
Action:
32-
- logs:*
33-
Resource: arn:aws:logs:*:*:*
34-
Roles:
35-
- !Ref LambdaRole
36-
37-
LambdaRole:
38-
Type: AWS::IAM::Role
39-
Properties:
40-
AssumeRolePolicyDocument:
41-
Version: '2012-10-17'
42-
Statement:
43-
- Action:
44-
- sts:AssumeRole
45-
Effect: Allow
46-
Principal:
47-
Service:
48-
- lambda.amazonaws.com
49-
Tags:
50-
- Key: Solution
51-
Value: ACFS3
52-
53-
CFNCustomProviderLogGroup:
54-
Type: AWS::Logs::LogGroup
55-
Properties:
56-
RetentionInDays: 7
57-
LogGroupName: !Sub '/aws/lambda/${CFNCustomProvider}'
58-
DependsOn:
59-
- CFNCustomProvider
60-
61-
CFNCustomProvider:
62-
Type: AWS::Serverless::Function
63-
Properties:
64-
CodeUri: s3://binxio-public-us-east-1/lambdas/cfn-certificate-provider-0.2.4.zip
65-
Description: CFN Certificate Domain Resource Record Provider
66-
MemorySize: 128
67-
Handler: provider.handler
68-
Timeout: 300
69-
Role: !GetAtt LambdaRole.Arn
70-
Runtime: python3.6
71-
726
S3BucketLogs:
737
Type: AWS::S3::Bucket
748
DeletionPolicy: Retain
@@ -135,7 +69,6 @@ Resources:
13569
- arn:aws:s3:::${TargetBucket}
13670
- TargetBucket: !Ref S3BucketRoot
13771

138-
13972
CopyFunction:
14073
Type: AWS::Serverless::Function
14174
Properties:
@@ -166,9 +99,6 @@ Outputs:
16699
S3BucketLogsName:
167100
Description: Logging bucket Name
168101
Value: !GetAtt S3BucketLogs.DomainName
169-
CFNCustomProvider:
170-
Description: ACM helper function
171-
Value: !GetAtt CFNCustomProvider.Arn
172102
CopyFunction:
173103
Description: S3 helper function
174104
Value: !GetAtt CopyFunction.Arn

templates/main.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Parameters:
2424
DomainName:
2525
Description: The part of a website address after your SubDomain - e.g. example.com
2626
Type: String
27+
HostedZoneId:
28+
Description: HostedZoneId for the domain e.g. Z23ABC4XYZL05B
29+
Type: String
2730
CreateApex:
2831
Description: Create an Apex Alias in CloudFront distribution - yes/no
2932
Type: String
@@ -46,9 +49,8 @@ Resources:
4649
Parameters:
4750
SubDomain: !Ref SubDomain
4851
DomainName: !Ref DomainName
49-
CFNCustomProvider: !GetAtt CustomResourceStack.Outputs.CFNCustomProvider
50-
CopyFunction: !GetAtt CustomResourceStack.Outputs.CopyFunction
5152
CreateApex: !Ref CreateApex
53+
HostedZoneId: !Ref HostedZoneId
5254
Tags:
5355
- Key: Solution
5456
Value: ACFS3
@@ -74,9 +76,6 @@ Resources:
7476
Outputs:
7577
SolutionVersion:
7678
Value: !FindInMap [Solution, Constants, Version]
77-
CFNCustomProvider:
78-
Description: ACM helper function
79-
Value: !GetAtt CustomResourceStack.Outputs.CFNCustomProvider
8079
CopyFunction:
8180
Description: S3 helper function
8281
Value: !GetAtt CustomResourceStack.Outputs.CopyFunction

0 commit comments

Comments
 (0)