I want to set up an EC2 instance running on a private VPC. It can connect to the Internet from the private VPC but can not access from outside. And there is a lambda function to trigger the EC2 to initiate some interactions with external resources (S3, Dynamo, Internet).
I have set up a VPC as following:
- An EC2 instance running docker in a private VPC subnet
- An ALB(application load-balancer) configured as internal and in private subnets (same as the EC2 subnet)
- A NAT Gateway which is working
- A lambda function which will do HTTPs GET and POST to the Internet and ALB
- Route53 private Hostzone has a record set that route "abcd.internal/api" to the ALB.
Here is the problem. The lambda function can connect to the Internet with HTTPs, but when it fails to HTTPs GET to the ALB with the private Hostzone record("abcd.internal").
My understanding is my ALB, EC2, lambda, NAT Gateway and Route53 are configured in the same VPC, they should be able to talk to each other with the private DNS name. I don't know why it fails.
Note: Before setting up a internal ALB, I did try setting up a internet-facing ALB in a public subnet, then configure a public Hostzone record set "abcd.public" to this ALB. It can talk to the EC2 instance and the EC2 instance can interact with the Internet through the NAT Gateway. So the "EC2 to Internet" part is working.
Update: I finally dig some error messages in lambda log as follows:
Error: Hostname/IP doesn't match certificate's altnames: "Host: abcd.internal. is not in the cert's altnames: DNS:.public"] reason: 'Host: abcd.internal. is not in the cert\'s altnames: DNS:.public', host: 'abcd.internal.',
That is interesting. I do have a public hostzone co-exist with the private hostzone, but the public hostzone is for other purpose. I dont know why the lambda function use the public DNS rather than the private DNS since it was configured inside a private subnet.