我正在尝试使用 AWS 的云开发工具包为我网站的某些子域创建 SSL 证书。问题是我正在使用 AWS Organizations 并且相关资源属于不同的 AWS 账户。我的域的托管区域是我们主帐户的一部分,但我正在运行 CDK 以在链接帐户中部署堆栈。这意味着DnsValidatedCertificate
该类能够请求一个新证书(在堆栈回滚后它们仍然在ACM中可见),但是当它尝试创建 DNS 记录以自动验证请求时会引发错误。
这是错误(我的帐号和堆栈名称已编辑):
5/6 | 22:44:14 | CREATE_FAILED | AWS::CloudFormation::CustomResource | SubSubDomainsCertificate/CertificateRequestorResource/Default (SubSubDomainsCertificateCertificateRequestorResourceBC626C85) Failed to create resource. User: arn:aws:sts::123456789012:assumed-role/MyStack-SubSubDomainsCertificateCertificat-16QRI74P8POO2/MyStack-SubSubDomainsCertificateCertificat-BXZ55WHIH1XC is not authorized to access this resource
new CustomResource (C:\repos\my-project\node_modules\@aws-cdk\aws-cloudformation\lib\custom-resource.ts:92:21)
\_ new DnsValidatedCertificate (C:\repos\my-project\node_modules\@aws-cdk\aws-certificatemanager\lib\dns-validated-certificate.ts:81:29)
\_ new MyStack (C:\repos\my-project\.elasticbeanstalk\api-stack.js:91:25)
这是相关的 CDK 代码(同样,HZ 和域已编辑):
// Executed with `cdk deploy --profile profileForLinkedAwsAccount`
const hostedZone = route53.HostedZone.fromHostedZoneAttributes(
this,
'MyDomainHostedZone',
{
hostedZoneId: 'Z2ABC1234RYN', // in master AWS account
zoneName: 'mydomain.com.'
}
);
const certificate = new certificatemanager.DnsValidatedCertificate(
this,
'SubSubDomainsCertificate',
{
domainName: `*.demo.mydomain.com`,
hostedZone,
region: 'us-east-1',
validationMethod: certificatemanager.ValidationMethod.DNS // ???
}
);
那么,是否有任何方法可以配置 CDK 以允许 DNS 验证自动发生?或者我是否需要使用不同的配置文件作为第二步?
编辑:根据迈克尔的建议,我添加了一个名为AWS主账户LinkedAccountCertValidatorRole
的角色。我附加到角色的托管策略及其信任关系如下所示。不幸的是,我仍然遇到同样的错误。此外,Access Advisor 选项卡表明该角色从未使用过该策略。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "route53:ChangeResourceRecordSets",
"Resource": "arn:aws:route53:::hostedzone/Z2ABC1234RYN"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}