AWS CDK跨帐户路由53
AWS CDK 定义:
- IAM角色,用于允许Route53记录的离散更改
- 跨帐户记录构造用于创建Route53跨帐户Route53记录
这些构造允许您创建Route53记录,其中区域存在于Cloudformation Stack的单独AWS帐户中。
开始
yarn add @fallobst22/cdk-cross-account-route53
首先在堆栈中为包含托管区域的AWS帐户创建角色。
// DNS Stack
const zone = new route53.PublicHostedZone(this, 'HostedZone', {
zoneName: 'example.com',
});
new CrossAccountRoute53Role(this, 'WebRoute53Role', {
roleName: 'WebRoute53Role',
assumedBy: new iam.AccountPrincipal('22222222'), // Web Stack Account
zone,
records: [{ domains: ['www.example.com'] }],
});
然后在子堆栈中创建记录
const hostedZoneId = 'Z12345'; // ID of the zone in the other account
const distribution = new cloudfront.Distribution(this, 'Distribution', {
domainNames: ['example.com'],
});
new CrossAccountRoute53RecordSet(this, 'ARecord', {
delegationRoleName: 'WebRoute53Role',
delegationRoleAccount: '111111111', // The account that contains the zone and role
hostedZoneId,
resourceRecordSets: [{
Name: `example.com`,
Type: 'A',
AliasTarget: {
DNSName: distribution.distributionDomainName,
HostedZoneId: 'Z2FDTNDATAQYW2', // Cloudfront Hosted Zone Id
EvaluateTargetHealth: false,
},
}],
});
CrossAccountRoute53Role
初始化器
new CrossAccountRoute53Role(scope: Construct, id: string, props: CrossAccountRoute53RoleProps)
参数
- 范围 构造
- id 字符串
- 道具 CrossAccountRoute53RoleProps
构建道具
| 名字 | 类型 | 描述 |
|---|---|---|
| roleName | string | 角色名称 |
| assumedBy | iam.IPrincipal | 允许承担角色的主体 |
| 区 | route53.IHostedZone | 托管分区。 |
| 记录 | CrossAccountRoute53RolePropsRecord[] | 该角色可以创建的记录 |
CrossAccountRoute53RolePropsRecords
| 名字 | 类型 | 描述 |
|---|---|---|
| 域名 | string | string[] | 可以创建或更改的记录的名称 |
| 类型 | route53.RecordType[] | 可以创建的记录类型。默认的 ['A', 'AAAA'] |
| 行动 | 'CREATE' | 'UPSERT' | 'DELETE' | 允许的操作。默认的 ['CREATE', 'UPSERT', 'DELETE'] |
CrossAccountRoute53RecordSet
初始化器
new CrossAccountRoute53RecordSet(scope: Construct, id: string, props: CrossAccountRoute53RecordSetProps)
参数
- 范围 构造
- id 字符串
- 道具 CrossAccountRoute53RecordSet
构建道具
| 名字 | 类型 | 描述 |
|---|---|---|
| delegationRoleName | string | 在具有托管分区的帐户中创建的角色名 |
| delegationRoleAccount | string | 托管区域的帐户的帐户标识符 |
| hostedZoneId | string | 主机分区id |
| resourceRecordSets | Route53.ResourceRecordSets | 要应用的更改。这些都是采用相同的格式 ChangeResourceRecordSets行动 |
发展现状
这些结构将保留 v0.x.x 有一段时间,允许更容易的bug修复和破坏性的变化 如果绝对需要的话.
一旦bug被修复(如果有的话),这些构造将被发布 v1 主版本,并将标记为稳定。
目前只测试了打字稿。
开发
npm run build将typescript编译为jsnpm run watch注意更改并编译npm run test执行jest单元测试