My stack looks like this (Python):
log_group = logs.LogGroup(
self,
"APIGatewayLogGroup",
retention=logs.RetentionDays.ONE_MONTH,
)
hosted_zone_id = Fn.import_value(self.config.hosted_zone_id_export_name)
hosted_zone = route53.HostedZone.from_hosted_zone_attributes(
self,
"HostedZone",
hosted_zone_id=hosted_zone_id,
zone_name=self.config.base_domain
)
certificate = acm.Certificate(
self,
"Certificate",
domain_name=self.config.domain,
validation=acm.CertificateValidation.from_dns(hosted_zone),
)
api = apigateway.RestApi(
self,
self.api_name,
rest_api_name=self.api_name,
description="API Gateway for APIs",
cloud_watch_role=True,
deploy=True,
deploy_options=apigateway.StageOptions(
access_log_destination=apigateway.LogGroupLogDestination(log_group),
access_log_format=apigateway.AccessLogFormat.clf(),
data_trace_enabled=True,
logging_level=apigateway.MethodLoggingLevel.INFO,
metrics_enabled=True,
),
default_method_options=apigateway.MethodOptions(
authorizer=self.authorizer,
authorization_type=apigateway.AuthorizationType.CUSTOM,
),
default_cors_preflight_options=apigateway.CorsOptions(
allow_origins=self.config.get_config("API_GATEWAY_CORS_ALLOW_ORIGINS"),
allow_methods=["GET", "POST", "DELETE", "OPTIONS"],
allow_headers=["*"],
),
domain_name=apigateway.DomainNameOptions(
domain_name=self.config.domain,
certificate=certificate,
endpoint_type=apigateway.EndpointType.EDGE,
security_policy=apigateway.SecurityPolicy.TLS_1_2
)
)
route53.RecordSet(
self,
"ARecord",
record_type=route53.RecordType.A,
zone=hosted_zone,
target=route53.RecordTarget.from_alias(targets.ApiGateway(api)),
)
When running CDK synth or deploy, I get this error
RuntimeError: Error: Resolution error: Resolution error: Trying to resolve() a Construct at /Resources/${Token[ApiStack.ARecord.Resource.LogicalID.843]}/Properties/aliasTarget/role/node..
I tried an alternative approach where I created the API in one stack, exported the ID, and created the record set in a separate stack using the imported ID. I got exactly the same error.
CDK version: 2.147.0 and aws-cdk-lib==2.147.0