Skip to content

Commit 4d92969

Browse files
committed
Create userpool domain
1 parent eae9a07 commit 4d92969

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

cfn-parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"CodeBranch": $env.GITHUB_REF_SLUG_CS,
66
"UserPoolName": $secrets.USER_POOL_NAME,
77
"UserPoolDomainName": $secrets.USER_POOL_DOMAIN_NAME,
8-
"DnsZoneId": "/org/dns/ZoneId",
8+
"ParentDnsZoneId": $secrets.PARENT_DNS_ZONE_ID,
99
"TargetOuIds": $secrets.DEPLOYMENT_TARGET_OU,
1010
"TargetRegions": "us-east-1",
1111
"TargetAccountIds": $secrets.DEPLOYMENT_TARGET_ACCOUNT_ID,

stacksets/userpool/stackset.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Parameters:
55
UserPoolName:
66
Type: String
77
Description: Name of UserPool
8+
UserPoolDomainName:
9+
Type: String
10+
Description: Name of UserPool Domain
11+
ParentDnsZoneId:
12+
Type: String
13+
Description: "Route53 Hosted Zone ID"
814

915
Resources:
1016
UserPool:
@@ -15,3 +21,40 @@ Resources:
1521
UserPoolName: !Ref UserPoolName
1622
AdminCreateUserConfig:
1723
AllowAdminCreateUserOnly: true
24+
25+
# DNS
26+
#
27+
# Cognito site verification requires either an A record at the root of the site's domain or a
28+
# delegation to another zone. Rathert than mess with the serverlessops.io apex record we
29+
# create a new zone for the user pool domain and add a delegation set to the parent zone.
30+
31+
AuthnzZone:
32+
Type: "AWS::Route53::HostedZone"
33+
Properties:
34+
Name: !Ref UserPoolDomainName
35+
HostedZoneConfig:
36+
Comment: ServerlessOps Authnz
37+
38+
AuthnzDelegationSet:
39+
Type: "AWS::Route53::RecordSet"
40+
Properties:
41+
HostedZoneId: !Ref ParentDnsZoneId
42+
Name: !Ref UserPoolDomainName
43+
Type: NS
44+
TTL: '3600'
45+
ResourceRecords: !GetAtt AuthnzZone.NameServers
46+
47+
SiteCertificate:
48+
Type: AWS::CertificateManager::Certificate
49+
DependsOn: AuthnzZone
50+
Properties:
51+
DomainName: !Ref UserPoolDomainName
52+
ValidationMethod: DNS
53+
54+
UserPoolDomain:
55+
Type: AWS::Cognito::UserPoolDomain
56+
Properties:
57+
Domain: !Ref UserPoolDomainName
58+
UserPoolId: !Ref UserPool
59+
CustomDomainConfig:
60+
CertificateArn: !Ref SiteCertificate

template.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Parameters:
1818
UserPoolName:
1919
Type: String
2020
Description: Name of UserPool
21+
UserPoolDomainName:
22+
Type: String
23+
Description: Name of UserPool Domain
24+
ParentDnsZoneId:
25+
Type: String
26+
Description: "Route53 Hosted Zone ID of parent zone"
2127

2228
Resources:
2329
UserPoolStackSet:
@@ -28,6 +34,10 @@ Resources:
2834
Parameters:
2935
- ParameterKey: UserPoolName
3036
ParameterValue: !Ref UserPoolName
37+
- ParameterKey: UserPoolDomainName
38+
ParameterValue: !Ref UserPoolDomainName
39+
- ParameterKey: ParentDnsZoneId
40+
ParameterValue: !Ref ParentDnsZoneId
3141
StackInstancesGroup:
3242
- DeploymentTargets:
3343
AccountFilterType: INTERSECTION

0 commit comments

Comments
 (0)