Search code examples
phpamazon-web-servicescomposer-phpamazon-elastic-beanstalkcoinbase-php

Composer.json Installation On AWS Elastic Beanstalk


I read in the AWS Elastic Beanstalk documentation that you can simply include the composer.json file in the root of your package and it will install an application and it's dependencies:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-configuration-composer

{
    "require": {
        "coinbase/coinbase": "~2.0"
    }
}

Then I created a PHP file with the following to test if it worked:

error_reporting(E_ALL);
ini_set('display_errors', 1);

$apiKey = 'workingkey';

$apiSecret = 'workingkey';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;

$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);

$buyPrice = $client->getBuyPrice('BTC-USD');

echo $buyPrice;

Unfortunately it gives the following error:

Fatal error: Uncaught Error: Class 'Coinbase\Wallet\Configuration' not found in /var/app/current/test.php:20 Stack trace: #0 {main} thrown in /var/app/current/test.php on line 20

I've tried everything I can think of to get this to work. What am I missing here?


Solution

  • You missed to include the autoloader of composer.

    Add this at the beginning of your file and it should work:

    require __DIR__.'/vendor/autoload.php';