aws / aws/aws-cdk

Route53.PrivateHostedZone: queryLogsLogGroupArn breaks cloudformation deployment with error "You can't create a query logging config for a private hosted zone."

Open
#27,986 2 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-route53 bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

I created a Route53 private hosted zone using TypeScript CDK. I then added a CloudWatch Logs log group, and tried to use the PrivateHostedZone construct's queryLogsLogGroupArn prop to send Route53 query logs to the log group. The CDK built the stack successfully but then the stack failed to deploy with CloudFormation returning this error:
```
Resource handler returned message: "You can't create a query logging config for a private hosted zone. (Service: Route53, Status Code: 400, Request ID: 83001f67-1dc7-45d5-a5b0-55dd62a5585f)" (RequestToken: f7446d50-3ec9-715e-5193-1cb6156e07d2, HandlerErrorCode: InvalidRequest)
```
This leads me to believe that the CDK is trying to deploy the wrong thing. Query logging for private hosted zones originates from the VPC, not the hosted zone itself, as is apparent in the L1 constructs CfnResolverQueryLoggingConfig and CfnResolverQueryLoggingConfigAssociation.

### Expected Behavior

I expected the PrivateHostedZone construct's queryLogsLogGroupArn prop to automatically hook up the private hosted zone VPC's query log output to the specified query log group ARN.

### Current Behavior

Stack deployment failed with this error:
```
5:47:37 PM | UPDATE_FAILED | AWS::Route53::HostedZone | HostedZoneDB99F866
Resource handler returned message: "You can't create a query logging config for a private hosted zone. (Service: Route53, Status Code: 400, Request ID: 83001f67-1dc7-45d5-a5b0-55dd62a5585f)" (RequestToken: f7446d50-3ec9-715e-5193-1cb6156e07d2, HandlerErrorCode: InvalidRequest)

❌ r53stack-new52-Beta failed: Error: The stack named r53stack-new52-Beta failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "You can't create a query logging config for a private hosted zone. (Service: Route53, Status Code: 400, Request ID: 83001f67-1dc7-45d5-a5b0-55dd62a5585f)" (RequestToken: f7446d50-3ec9-715e-5193-1cb6156e07d2, HandlerErrorCode: InvalidRequest)
at FullCloudFormationDeployment.monitorDeployment (/Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:467:10232)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.deployStack2 [as deployStack] (/Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:470:180228)
at async /Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:470:163476

❌ Deployment failed: Error: The stack named r53stack-new52-Beta failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "You can't create a query logging config for a private hosted zone. (Service: Route53, Status Code: 400, Request ID: 83001f67-1dc7-45d5-a5b0-55dd62a5585f)" (RequestToken: f7446d50-3ec9-715e-5193-1cb6156e07d2, HandlerErrorCode: InvalidRequest)
at FullCloudFormationDeployment.monitorDeployment (/Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:467:10232)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.deployStack2 [as deployStack] (/Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:470:180228)
at async /Users/imesona/brazil-pkg-cache/packages/CDKBuild/CDKBuild-4.x.222392.0/AL2_x86_64/DEV.STD.PTHREAD/build/staging-cdk/node_modules/aws-cdk/lib/index.js:470:163476

The stack named r53stack-new52-Beta failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "You can't create a query logging config for a private hosted zone. (Service: Route53, Status Code: 400, Request ID: 83001f67-1dc7-45d5-a5b0-55dd62a5585f)" (RequestToken: f7446d50-3ec9-715e-5193-1cb6156e07d2, HandlerErrorCode: InvalidRequest)
› Error: Failed to run CDK CLI

BUILD FAILED

*** command 'cdk-build' with arguments 'cdk deploy r53stack-new52-Beta' exited with return code '1'

```

### Reproduction Steps

Relevant chunks to produce the failure:
```ts
const vpc = new ec2.Vpc(this, 'DnsVpc', {
ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
enableDnsHostnames: true,
enableDnsSupport: true,
subnetConfiguration: [
{
cidrMask: 26,
name: 'resolver_endpoint_subnet',
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
}
]
});

const queryLogGroup = new logs.LogGroup(this, 'QueryLogGroup');

const privateHostedZone = new route53.PrivateHostedZone(this, 'HostedZone', {
zoneName: 'myPrivateHostedZone',
vpc,
queryLogsLogGroupArn: queryLogGroup.logGroupArn
});
```

### Possible Solution

I'm guessing that the PrivateHostedZone construct is reusing code from the (public) HostedZone construct, which also has a queryLogsLogGroupArn prop. However for private hosted zones, the query logging happens at the VPC, not the Hosted Zone. So maybe the PrivateHostedZone construct needs to be updated so it's smart enough to figure out its primary VPC (see footnote) and in the background sets up the cfnResolverQueryLoggingConfigAssociation between that VPC and the log group.

footnote: Is it possible to determine a "primary" VPC for a private hosted zone? Private hosted zones can be associated with many VPCs, including cross-account. Maybe this would require an explicit VPC argument to go along with the queryLogsLogGroupArn argument, or maybe this would be better-suited as a VPC construct update.

### Additional Information/Context

You can work around this issue using the L1 constructs, as I did here:
```
const queryLogGroup = new logs.LogGroup(this, 'QueryLogGroup');
const cfnResolverQueryLoggingConfig = new route53resolver.CfnResolverQueryLoggingConfig(this, 'MyCfnResolverQueryLoggingConfig', {
destinationArn: queryLogGroup.logGroupArn,
name: 'r53VpcQueryLoggingConfig',
});
const cfnResolverQueryLoggingConfigAssociation = new route53resolver.CfnResolverQueryLoggingConfigAssociation(this, 'MyCfnResolverQueryLoggingConfigAssociation', /* all optional props */ {
resolverQueryLogConfigId: cfnResolverQueryLoggingConfig.attrId,
resourceId: vpc.vpcId,
});

const privateHostedZone = new route53.PrivateHostedZone(this, 'HostedZone', {
zoneName: props.zoneName,
vpc
});
```

### CDK CLI Version

2.103.1 (build 3bb19ac)

### Framework Version

_No response_

### Node.js Version

18

### OS

Mac

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the TypeScript route53.PrivateHostedZone construct and its queryLogsLogGroupArn handling; compare it with the public HostedZone path and inspect the synthesized CloudFormation. Reproduce the VPC, log group, and private hosted zone example, then examine the CfnResolverQueryLoggingConfig and CfnResolverQueryLoggingConfigAssociation entry points. Done means the construct no longer attempts an invalid private-hosted-zone query logging configuration and the VPC association behavior is defined for multiple or cross-account VPCs.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.