title: Elastic Beanstalk fails to launch in custom VPC and subnet
body: <p>My Elastic Beanstalk env fails to launch due to connectivity between the EC2 and Elastic Beanstalk:</p>
  <pre class="lang-sh prettyprint-override"><code> Error: Error waiting for Elastic Beanstalk Environment (e-xxxxxxxxxx) to become ready: 2 errors occurred:
  
      * 2021-02-16 11:00:21.529 +0000 UTC (e-xxxxxxxxxx) : 
              Stack named 'awseb-e-xxxxxxxxxx-stack' aborted operation. Current state: 'CREATE_FAILED'  
              Reason: The following resource(s) failed to create: [AWSEBInstanceLaunchWaitCondition].
  
      * 2021-02-16 11:00:21.662 +0000 UTC (e-xxxxxxxxxx) : 
              The EC2 instances failed to communicate with AWS Elastic Beanstalk, either because of configuration problems with the VPC or a failed EC2 instance. Check your VPC configuration and try launching the environment again.
  </code></pre>
  <p>However, I can SSH into the EC2 instance, where I find the following:</p>
  <pre class="lang-sh prettyprint-override"><code>$ tail /var/log/eb-cfn-init.log 
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0     0    0     0    0     0      0      0 --:--:--  0:02:09 --:--:--     0curl: (7) Failed to connect to elasticbeanstalk-platform-assets-eu-west-2.s3.eu-west-2.amazonaws.com port 443: Connection timed out
  + RESULT=7
  + [[ 7 -ne 0 ]]
  + sleep_delay
  + ((  40 &lt; 3600  ))
  + echo Sleeping 40
  Sleeping 40
  + sleep 40
  
  </code></pre>
  <p>This error surprises me, because I have an S3 VPC endpoint in this VPC:</p>
  <pre><code>resource &quot;aws_vpc_endpoint&quot; &quot;s3_endpoint_public&quot; {
    vpc_id       = aws_vpc.main.id
    service_name = &quot;com.amazonaws.${var.aws_region}.s3&quot;
  }
  
  resource &quot;aws_vpc_endpoint_route_table_association&quot; &quot;s3_public_route_table_association&quot; {
    route_table_id  = aws_route_table.public.id
    vpc_endpoint_id = aws_vpc_endpoint.s3_endpoint_public.id
  }
  </code></pre>
  <p>How can I debug / fix my Elastic Beanstalk environment?</p>
  <hr />
  <p>Route table / subnet configuration</p>
  <pre><code>resource &quot;aws_route_table&quot; &quot;public&quot; {
    vpc_id = aws_vpc.main.id
  }
  
  resource &quot;aws_route_table_association&quot; &quot;public_a&quot; {
    route_table_id = aws_route_table.public.id
    subnet_id      = aws_subnet.public_c.id
  }
  
  resource &quot;aws_route_table_association&quot; &quot;public_b&quot; {
    route_table_id = aws_route_table.public.id
    subnet_id      = aws_subnet.public_c.id
  }
  
  resource &quot;aws_route_table_association&quot; &quot;public_c&quot; {
    route_table_id = aws_route_table.public.id
    subnet_id      = aws_subnet.public_c.id
  }
  
  resource &quot;aws_internet_gateway&quot; &quot;public&quot; {
    vpc_id = aws_vpc.main.id
  }
  
  resource &quot;aws_route&quot; &quot;public_internet&quot; {
    route_table_id = aws_route_table.public.id
    gateway_id     = aws_internet_gateway.public.id
  
    destination_cidr_block = &quot;0.0.0.0/0&quot;
  }
  </code></pre>