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?
CodeBuild does not have specific requirements for outbound traffic, but you must allow access to any Internet resources required for your build, such as GitHub or Amazon S3.
Build commands run as root by default Cause: By default, CodeBuild runs all build commands as the root user.
A NAT gateway is a Network Address Translation (NAT) service. You can use a NAT gateway so that instances in a private subnet can connect to services outside your VPC but external services cannot initiate a connection with those instances.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With