Reputation: 5604
I am experimenting with CodeBuild but have reached a dead-end. My build always fails with the error message:
Build does not have internet connectivity. Please check subnet network configuration.
I checked the VPC configuration (subnet, security groups), and they seem okay. To test internet connectivity, I launched an EC2 instance in the same subnet, and it is able to communicate with external services (I tried a ping and some HTTP GETs).
How do I resolve this 'internet connectivity' issue?
Upvotes: 25
Views: 12368
Reputation: 441
When you are assigning the CodeBuild project to a subnet, it must be a private subnet with a NAT gateway that is connected to the internet gateway.
I had this same issue, but I was quite early in the project so I could tear it down and start again.
From the VPC Dashboard I used the 'Start VPC Wizard' button where I could select a template named 'VPC with Public and Private Subnets'. I still had to create the security groups and assign an elastic IP.
Once the new VPC was generated and configured I reconfigured my CodeBuild project to use the private subnet in the new VPC and the provisioning step succeeded.
I hope this helps.
Upvotes: 27
Reputation: 1650
CodeBuild builds require a NAT Gateway to reach the internet, because they do not get assigned a public IP address like an EC2 instance does in a public subnet. You can think of it like CodeBuild builds are always in a private subnet in your VPC: https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html
See this documentation for more troubleshooting steps, including a CloudFormation template for setting up a VPC with a NAT Gateway: https://docs.aws.amazon.com/codebuild/latest/userguide/vpc-support.html#troubleshooting
Upvotes: 16