{"id":9524,"library":"aws-cdk-aws-route53-targets","title":"AWS CDK Route53 Targets (CDK v1)","description":"The `aws-cdk-aws-route53-targets` library provides AWS CDK constructs for creating Route53 Alias records that point to various AWS resources like S3 static websites, CloudFront distributions, API Gateway custom domains, and Elastic Load Balancers. It extends `aws-cdk.aws-route53` by offering convenient alias targets. This specific package (version 1.x.x) is designed for AWS CDK v1 applications. AWS CDK follows a monthly release cadence, aligning with new AWS service features and updates.","status":"active","version":"1.204.0","language":"en","source_language":"en","source_url":"https://github.com/aws/aws-cdk.git","tags":["aws","cdk","route53","dns","alias","target","cloudformation"],"install":[{"cmd":"pip install aws-cdk-aws-route53-targets","lang":"bash","label":"Install for CDK v1"}],"dependencies":[{"reason":"Core AWS CDK constructs and application lifecycle.","package":"aws-cdk.core","optional":false},{"reason":"Base constructs for AWS Route53 resources.","package":"aws-cdk.aws-route53","optional":false},{"reason":"Required for S3BucketWebsiteTarget examples.","package":"aws-cdk.aws-s3","optional":true},{"reason":"Required for CloudFrontTarget examples.","package":"aws-cdk.aws-cloudfront","optional":true}],"imports":[{"note":"S3BucketWebsiteTarget and other targets are in the dedicated 'targets' package for CDK v1, not directly in 'aws_route53'.","wrong":"from aws_cdk.aws_route53 import S3BucketWebsiteTarget","symbol":"S3BucketWebsiteTarget","correct":"from aws_cdk.aws_route53_targets import S3BucketWebsiteTarget"},{"note":"CDK v2 uses 'aws_cdk_lib' and integrates targets; this package is specifically for CDK v1's separate target library.","wrong":"from aws_cdk.lib.aws_route53 import CloudFrontTarget","symbol":"CloudFrontTarget","correct":"from aws_cdk.aws_route53_targets import CloudFrontTarget"},{"symbol":"ApiGatewayDomain","correct":"from aws_cdk.aws_route53_targets import ApiGatewayDomain"}],"quickstart":{"code":"import os\nfrom aws_cdk import App, Stack, Duration\nfrom aws_cdk import aws_s3 as s3\nfrom aws_cdk import aws_route53 as route53\nfrom aws_cdk.aws_route53_targets import S3BucketWebsiteTarget # This is the key import for this library\n\nclass MyRoute53Stack(Stack):\n    def __init__(self, scope, id, **kwargs):\n        super().__init__(scope, id, **kwargs)\n\n        # In a real scenario, you'd import an existing Hosted Zone:\n        # hosted_zone = route53.HostedZone.from_lookup(self, \"MyZone\", domain_name=\"example.com\")\n        # For a runnable example, we'll create a dummy one (will create a Route 53 zone).\n        # Replace 'myexampledomain.com' with your actual domain name.\n        hosted_zone = route53.HostedZone(self, \"MyZone\",\n            zone_name=\"myexampledomain.com\"\n        )\n\n        # Create an S3 bucket configured for static website hosting\n        website_bucket = s3.Bucket(self, \"WebsiteBucket\",\n            bucket_name=\"www.myexampledomain.com\", # Must match the domain for S3 website hosting\n            website_index_document=\"index.html\",\n            public_read_access=True # Required for public website hosting\n        )\n\n        # Create an A record pointing to the S3 bucket website using S3BucketWebsiteTarget\n        route53.ARecord(self, \"WebsiteAliasRecord\",\n            zone=hosted_zone,\n            target=route53.RecordTarget.from_alias(S3BucketWebsiteTarget(website_bucket)),\n            record_name=\"www\" # This will create 'www.myexampledomain.com'\n        )\n\napp = App()\nMyRoute53Stack(app, \"MyRoute53Stack\")\napp.synth()","lang":"python","description":"This example demonstrates how to create an AWS CDK application (for CDK v1) that provisions an S3 static website and then creates an AWS Route53 A-alias record pointing to that S3 bucket. It utilizes the `S3BucketWebsiteTarget` from the `aws-cdk-aws-route53-targets` library to simplify the alias configuration. Remember to replace `myexampledomain.com` with your own registered domain name for actual deployment."},"warnings":[{"fix":"Migrate to CDK v2 and use `from aws_cdk.aws_route53 import S3BucketWebsiteTarget` (or similar) directly, without installing `aws-cdk-aws-route53-targets`.","message":"This `aws-cdk-aws-route53-targets` package is for AWS CDK v1 ONLY. For AWS CDK v2, all alias targets are integrated directly into the `aws-cdk-lib.aws_route53` module. Do NOT install this package if you are using CDK v2 (`aws-cdk-lib`).","severity":"breaking","affected_versions":"CDK v2 (2.x.x) users"},{"fix":"Ensure the underlying AWS resource referenced by the target is properly configured and provisioned according to its service's requirements (e.g., `website_index_document`, `public_read_access` for S3).","message":"The target resource (e.g., S3 bucket) must be configured correctly for the alias target to work. For `S3BucketWebsiteTarget`, the S3 bucket must have static website hosting enabled and be publicly accessible. For `CloudFrontTarget`, the distribution must be deployed.","severity":"gotcha","affected_versions":"All v1 versions"},{"fix":"Wrap your target object: `target=route53.RecordTarget.from_alias(MySpecificTarget(resource))`.","message":"When creating records, always use `route53.RecordTarget.from_alias()` with a target from this library. Directly assigning a raw construct will likely result in an error or an incorrect record type.","severity":"gotcha","affected_versions":"All v1 versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"For CDK v1: `pip install aws-cdk-aws-route53-targets`. For CDK v2: Do not install this package; targets are directly in `aws_cdk.aws_route53` (e.g., `from aws_cdk.aws_route53 import S3BucketWebsiteTarget`).","cause":"The `aws-cdk-aws-route53-targets` package is not installed in your Python environment, or you are running CDK v2 and mistakenly expecting this package to be present.","error":"ModuleNotFoundError: No module named 'aws_cdk.aws_route53_targets'"},{"fix":"For CDK v1: Correct the import to `from aws_cdk.aws_route53_targets import S3BucketWebsiteTarget`. For CDK v2: Ensure `aws-cdk-lib` is installed and the import is `from aws_cdk.aws_route53 import S3BucketWebsiteTarget`.","cause":"You are trying to import a target construct directly from `aws_cdk.aws_route53` while using AWS CDK v1, or you are using CDK v2 but have not installed `aws-cdk-lib` correctly.","error":"AttributeError: module 'aws_cdk.aws_route53' has no attribute 'S3BucketWebsiteTarget'"},{"fix":"Ensure all `aws-cdk.*` packages are on the *exact same* major.minor.patch version (e.g., all `1.204.0`). If using CDK v2, uninstall all `aws-cdk.*` and install only `aws-cdk-lib`.","cause":"This usually indicates a version mismatch between your `aws-cdk.core`, `aws-cdk.aws-route53`, and `aws-cdk-aws-route53-targets` packages, or attempting to mix CDK v1 constructs with a CDK v2 application context.","error":"JSII error: Type 'aws_cdk.aws_route53_targets.S3BucketWebsiteTarget' is not assignable to type 'aws_cdk.aws_route53.IRoute53RecordTarget'"}]}