I am trying to create an AWS IoT VPC interface endpoint. I am using terraform. Each AWS account comes with an IoT Core endpoint like this: xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com
They can be pinged from public internet.
Here is the code I am trying: Created a VPC with Internet gateway, Route tables and public subnets (easier to test, later will do it in private subnet). Created a security group which has allows incoming traffic on port 443, 80, 8883, 8 (ICMP) for CIDR "172.16.0.0/16". Outgoing allowed on all ports and all IP's.
Endpoint generating code:
resource "aws_vpc_endpoint" "iot_core_vpc_interface_endpoint" {
vpc_id = aws_vpc.main.id
vpc_endpoint_type = "Interface"
subnet_ids = [for subnet in aws_subnet.public_web_subnets : subnet.id]
service_name = "com.amazonaws.us-east-1.iot.data"
private_dns_enabled = false
security_group_ids = [aws_security_group.endpoint_security_group.id]
}
For private hosted zone
data "aws_iot_endpoint" "iot_endpoint" {
endpoint_type = "iot:Data-ATS"
}
resource "aws_route53_zone" "iot_private_hosted_zone" {
name = data.aws_iot_endpoint.iot_endpoint.endpoint_address
vpc {
vpc_id = aws_vpc.main.id
vpc_region = var.region
}
}
Finally the Route 53 settings.
resource "aws_route53_record" "www" {
zone_id = aws_route53_zone.iot_private_hosted_zone.zone_id
name = data.aws_iot_endpoint.iot_endpoint.endpoint_address
type = "A"
alias {
name = aws_vpc_endpoint.iot_core_vpc_interface_endpoint.dns_entry[0].dns_name
zone_id = aws_vpc_endpoint.iot_core_vpc_interface_endpoint.dns_entry[0].hosted_zone_id
evaluate_target_health = true
}
}
I created an EC2 instance in the same public subnet, attached the same security group and tried to ping the endpoint xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com from it but it gave no answer.
dig xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com
gave the private IPs associated with the VPC endpoint.
When I remove the Route 53 hosted zone and the records, I am able to ping the endpoint. I guess it just starts sending traffic over internet rather than the VPC Endpoint.
I think I am missing out on some small but important detail here.
More details: Thanks to response of @wikeegan I tried this from my EC2 instance and got this:
sh-5.2$ curl -v xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com:8883
* Host xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com:8883 was resolved.
* IPv6: (none)
* IPv4: 172.16.1.249, 172.16.2.91, 172.16.3.221
* Trying 172.16.1.249:8883...
* Connected to xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com (172.16.1.249) port 8883
> GET / HTTP/1.1
> Host: xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com:8883
> User-Agent: curl/8.5.0
> Accept: */*
I am trying to come up with a simple explanation as to what is happening.
Within your private hosted zone, create an alias record for each elastic network interface IP for the VPC endpoint.. Are they the same as the endpoint address of the IoT endpoint?private_dns_enabled = trueon the endpoint, and let AWS manage associating that address with your VPC? When you do that, you don't need to create a Route53 private hosted zone or any DNS records yourself. Also, make sure you haveenable_dns_support = trueon your VPC.