|
| 1 | +--- |
| 2 | +layout: "aws" |
| 3 | +page_title: "AWS: aws_api_gateway_domain_name" |
| 4 | +sidebar_current: "docs-aws-resource-api-gateway-domain-name" |
| 5 | +description: |- |
| 6 | + Registers a custom domain name for use with AWS API Gateway. |
| 7 | +--- |
| 8 | + |
| 9 | +# aws\_api\_gateway\_domain\_name |
| 10 | + |
| 11 | +Registers a custom domain name for use with AWS API Gateway. |
| 12 | + |
| 13 | +This resource just establishes ownership of and the TLS settings for |
| 14 | +a particular domain name. An API can be attached to a particular path |
| 15 | +under the registered domain name using |
| 16 | +[the `aws_api_gateway_base_path_mapping` resource](api_gateway_base_path_mapping.html). |
| 17 | + |
| 18 | +Internally API Gateway creates a CloudFront distribution to |
| 19 | +route requests on the given hostname. In addition to this resource |
| 20 | +it's necessary to create a DNS record corresponding to the |
| 21 | +given domain name which is an alias (either Route53 alias or |
| 22 | +traditional CNAME) to the Cloudfront domain name exported in the |
| 23 | +`cloudfront_domain_name` attribute. |
| 24 | + |
| 25 | +## Example Usage |
| 26 | + |
| 27 | +``` |
| 28 | +resource "aws_api_gateway_domain_name" "example" { |
| 29 | + domain_name = "api.example.com" |
| 30 | +
|
| 31 | + certificate_name = "example-api" |
| 32 | + certificate_body = "${file("${path.module}/example.com/example.crt")}" |
| 33 | + certificate_chain = "${file("${path.module}/example.com/ca.crt")}" |
| 34 | + certificate_private_key = "${file("${path.module}/example.com/example.key")}" |
| 35 | +} |
| 36 | +
|
| 37 | +# Example DNS record using Route53. |
| 38 | +# Route53 is not specifically required; any DNS host can be used. |
| 39 | +resource "aws_route53_record" "example" { |
| 40 | + zone_id = "${aws_route53_zone.example.id}" # See aws_route53_zone for how to create this |
| 41 | +
|
| 42 | + name = "${aws_api_gateway_domain_name.example.domain_name}" |
| 43 | + type = "A" |
| 44 | +
|
| 45 | + alias { |
| 46 | + name = "${aws_api_gateway_domain_name.example.cloudfront_domain_name}" |
| 47 | + zone_id = "${aws_api_gateway_domain_name.example.cloudfront_zone_id}" |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Argument Reference |
| 53 | + |
| 54 | +The following arguments are supported: |
| 55 | + |
| 56 | +* `domain_name` - (Required) The fully-qualified domain name to register |
| 57 | +* `certificate_name` - (Required) The unique name to use when registering this |
| 58 | + cert as an IAM server certificate |
| 59 | +* `certificate_body` - (Required) The certificate issued for the domain name |
| 60 | + being registered, in PEM format |
| 61 | +* `certificate_chain` - (Required) The certificate for the CA that issued the |
| 62 | + certificate, along with any intermediate CA certificates required to |
| 63 | + create an unbroken chain to a certificate trusted by the intended API clients. |
| 64 | +* `certificate_private_key` - (Required) The private key associated with the |
| 65 | + domain certificate given in `certificate_body`. |
| 66 | + |
| 67 | +## Attributes Reference |
| 68 | + |
| 69 | +The following attributes are exported: |
| 70 | + |
| 71 | +* `id` - The internal id assigned to this domain name by API Gateway. |
| 72 | +* `cloudfront_domain_name` - The hostname created by Cloudfront to represent |
| 73 | + the distribution that implements this domain name mapping. |
| 74 | +* `cloudfront_zone_id` - For convenience, the hosted zone id (`Z2FDTNDATAQYW2`) |
| 75 | + that can be used to create a Route53 alias record for the distribution. |
0 commit comments