Package: cdk-cross-account-route53
AWS CDK Cross Account Route53AWSCDKConstructs that define:IAM role that can be used to allow discrete Route53 Record changesCross Account Record construct to create Route53 cross account Route53 recordsThese constructs allow you to create Route53 records where the zone exists in a separate AWS account to the Cloudformation Stack.Getting startedyarnaddcdk-cross-account-route53First create the role in the stack for the AWS account which contains the hosted zone.//DNSStackconstzone=newroute53.PublicHostedZone(this,'HostedZone',{zoneName:'example.com',});newCrossAccountRoute53Role(this,'WebRoute53Role',{roleName:'WebRoute53Role',assumedBy:newiam.AccountPrincipal('22222222'),//WebStackAccountzone,records:[{domainNames:'www.example.com'}],});Then in the child stack create the recordsconsthostedZoneId='Z12345';//IDofthezoneintheotheraccountconstdistribution=newcloudfront.Distribution(this,'Distribution',{domainNames:['example.com'],});newCrossAccountRoute53RecordSet(this,'ARecord',{delegationRoleName:'WebRoute53Role',delegationRoleAccount:'111111111',//TheaccountthatcontainsthezoneandrolehostedZoneId,resourceRecordSets:[{Name:`example.com`,Type:'A',AliasTarget:{DNSName:distribution.distributionDomainName,HostedZoneId:'Z2FDTNDATAQYW2',//CloudfrontHostedZoneIdEvaluateTargetHealth:false,},}],});If you want to use wildcard matching on domains you can choose to not autonormalise the domains and pass in a wildcard e.g.newCrossAccountRoute53Role(this,'WebRoute53Role',{roleName:'WebRoute53Role',assumedBy:newiam.AccountPrincipal('22222222'),//WebStackAccountzone,records:[{domainNames:'*.example.com'}],normaliseDomains:false,});CrossAccountRoute53RoleInitializernewCrossAccountRoute53Role(scope:Construct,id:string,props:CrossAccountRoute53RoleProps)ParametersscopeConstructidstringpropsCrossAccountRoute53RolePropsConstruct PropsNameTypeDescriptionroleNamestringThe role nameassumedByiam.IPrincipalThe principals that are allowed to assume the rolezoneroute53.IHostedZoneThe hosted zone.recordsCrossAccountRoute53RolePropsRecord[]The records that can be created by this rolenormaliseDomainsbooleanNormalise the domains names as per AWS documentation (default: true)CrossAccountRoute53RolePropsRecordsNameTypeDescriptiondomainNamesstring | string[]The names of the records that can be created or changedtypesroute53.RecordType[]The typepsof records that can be created. Default['A', 'AAAA']actions'CREATE' | 'UPSERT' | 'DELETE'The allowed actions. Default['CREATE', 'UPSERT', 'DELETE']CrossAccountRoute53RecordSetInitializernewCrossAccountRoute53RecordSet(scope:Construct,id:string,props:CrossAccountRoute53RecordSetProps)ParametersscopeConstructidstringpropsCrossAccountRoute53RecordSetConstruct PropsNameTypeDescriptiondelegationRoleNamestringThe role name created in the account with the hosted zonedelegationRoleAccountstringThe account identfier of the account with the hosted zonehostedZoneIdstringThe hosted zoned idresourceRecordSetsRoute53.ResourceRecordSetsThe changes to be applied. These are in the same format as taken byChangeResourceRecordSets ActionDevelopment StatusThese constructs will stay inv0.x.xfor a while, to allow easier bug fixing & breaking changesif absolutely needed.
Once bugs are fixed (if any), the constructs will be published withv1major version and will be marked as stable.Only typescript has been tested.Developmentnpm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit tests