I'm trying to use AWS' Cloud Development Kit to create an SSL certificate for some sub-subdomains of my website. The trouble is that I'm using AWS Organizations and the relavant resources belong to different AWS accounts. The hosted zone for my domain is part of our master account, but I'm running CDK to deploy a stack in a linked account. This means that the DnsValidatedCertificate
class is able to request a new certificate (they're still visible in ACM after the stack is rolled back), but it throws an error when it attempts to create a DNS record to automatically validate the request.
Here's the error (with my account number and stack name redacted):
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)
And here's the relevant piece of CDK code (again, with HZ & domain redacted):
// 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 // ???
}
);
So, is there any way to configure CDK that will allow the DNS validation to happen automatically? Or do I need to do that as a second step, using a different profile?
EDIT: Based on Michael's suggestion, I added a role named LinkedAccountCertValidatorRole
to the master AWS account. The managed policy I've attached to the role and it's trust relationship are shown below. Unfortunately, I'm still getting the same error. In addition, the Access Advisor tab indicates that the policy was never used by this role.
{
"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": {}
}
]
}