Search code examples
phpamazon-web-servicesamazon-rdsaws-codebuild

AWS CodeBuild fails to interact with RDS instance


I have the most basic setup in AWS:

  • a publicly accessible RDS instance (PostgreSQL 9.6.6 - same as my development one)
  • a CodeBuild project

both in the default VPC.

My application is written in Laravel 5.5 and the buildspec.yml runs ./artisan migrate --force at some point and CodeBuild outputs the following error:

[Container] 2018/03/10 19:41:36 Running command php artisan migrate --force

[Illuminate\Database\QueryException] 
SQLSTATE[08006] [7] timeout expired (SQL: select * from information_schema. 
tables where table_schema = public and table_name = migrations)     

[Doctrine\DBAL\Driver\PDOException] 
SQLSTATE[08006] [7] timeout expired    

[PDOException] 
SQLSTATE[08006] [7] timeout expired 

Where should I start looking for an error?


Solution

  • You need to make sure that the RDS security group allows inbound traffic from Code Build.

    1. Go to https://ip-ranges.amazonaws.com/ip-ranges.json
    2. Search for CODEBUILD and choose your region.
    3. Add the IP to the inbound rule in the RDS Security Groups.