0

I am fiddling with this issue and cannot resolve it - just wanted to check if anyone here can help with tips

I am loading the class and calling the constructor like this

include_once './Myaws.php';
$aws = new Myaws();
$aws->bucket = $images['config']['bucket'];

Myaws.php is as follows

class Myaws {

    public $bucket;    

    function __construct() {        
        $this->aws = Aws::factory('./config/aws_config.php');
    }

}

It works like a charm!

Now the issue

The './config/aws_config.php' is just an array that will change depending on the deployment stage - so I want to make it dynamic. Here is what I do and it doesnt work

include_once './Myaws.php';
$aws = new Myaws();
$aws->bucket = $images['config']['bucket'];
$aws->config = $images['config']['awsconfig'];

And in the Myaws.php, I change the following

class Myaws {

    public $bucket;    
    public $config;    

    function __construct() {        
        $this->aws = Aws::factory($this->config);
    }

}

It doesn't work :( and neither does the below one

include_once './Myaws.php';
$aws = new Myaws($images['config']['awsconfig']);
$aws->bucket = $images['config']['bucket'];

class Myaws {

    public $bucket;    

    function __construct($config) {        
        $this->aws = Aws::factory($config);
    }

}

This is pretty basic Oops and I don't seem to get it I think. Can anyone suggest me how can I make that variable $config dynamic?

4
  • 1
    Does 'images' refer to an AMI? print_r($config) and make sure you're passing what you think you are. Also might need to elaborate on 'doesn't work' Commented Sep 23, 2013 at 0:49
  • I see no reason why your last example wouldn't work. Does PHP or the Aws class trigger any errors? Commented Sep 23, 2013 at 0:56
  • Basically, Aws::factory('./config/aws_config.php') takes an array as input and if I input an array directly it works, if I put as a config file it works but it doesnt if I do it in the way I showed you folks. Commented Sep 23, 2013 at 3:19
  • The AWS class gives a missing security credentials error showing that the passed value never reaches. Images is just an array... I shall still dig in more... Commented Sep 23, 2013 at 3:20

1 Answer 1

3

I found the formatting on the included file vs in a passed array to be not 100% compatible. Also check the in the api docs how they use my_profile to pass those credentials.

here is a example of the current method I am using to generation the config

$aws = Aws::factory($this->getAwsConfig());


   private function getAwsConfig()
{
    return array(
        // Bootstrap the configuration file with AWS specific features
        'credentials' => array(
            'key' => $this->awsKey,
            'secret' => $this->awsSecret
        ),
        'includes' => array('_aws'),
        'services' => array(
            // All AWS clients extend from 'default_settings'. Here we are
            // overriding 'default_settings' with our default credentials and
            // providing a default region setting.
            'default_settings' => array(
                'params' => array(
                    'region' => $this->awsRegion
                )
            )
        )
    );

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.