Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CodeBuild – Build does not have internet connectivity. Please check subnet network configuration

Tags:

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?

like image 314
John Keyes Avatar asked Jan 30 '18 13:01

John Keyes


People also ask

Does CodeBuild have Internet access?

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.

Does CodeBuild run as root?

Build commands run as root by default Cause: By default, CodeBuild runs all build commands as the root user.

Can NAT gateway be in private subnet?

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.


2 Answers

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.

like image 111
Mark Allen Avatar answered Sep 29 '22 10:09

Mark Allen


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

like image 32
Clare Liguori Avatar answered Sep 29 '22 10:09

Clare Liguori