Wednesday, May 27, 2015

Installing the AWS SDK for PHP onto my Raspberry Pi

Just some notes for my own reference on getting the AWS SDK for PHP working on my RaspberryPi.

1. Installed PHP and Apache (needed for this particular project)

pi@raspberrypi ~ $ sudo apt-get install apache2 php5 libapache2-mod-php5

2. Moved my project folder and created the composer.json file (as per the SDK installation instructions).

nano composer.json

3. Popped in the required JSON.

    "require": {
        "aws/aws-sdk-php": "2.*"


4. Ran the installer and ... bop-bow! ....

pi@raspberrypi ~/phpscripts/greenmode $ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1

    - aws/aws-sdk-php 2.4.0 requires guzzle/guzzle ~3.7.0 -> satisfiable by guzzle/guzzle[v3.7.0, v3.7.1, v3.7.2, v3.7.3, v3.7.4].

... and

 guzzle/guzzle v3.9.3 requires ext-curl * -> the requested PHP extension curl is missing from your system.

4. Loaded up the php5-curl package ....

pi@raspberrypi /var/www $ sudo apt-get install php5-curl

5. Everything working!

pi@raspberrypi ~/phpscripts/greenmode $ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing symfony/event-dispatcher (v2.6.8)
    Downloading: 100%         

  - Installing guzzle/guzzle (v3.9.3)
    Downloading: 100%         

  - Installing aws/aws-sdk-php (2.8.7)
    Downloading: 100%    

Just to be sure ... let's do something .... 

A quick Ec2 iterator script ...


        require 'vendor/autoload.php';

        $ec2Client = \Aws\Ec2\Ec2Client::factory(array(
                'profile' => 'dev',
                'region'  => 'ap-southeast-2'

        function allInstances(){

                $iterator = $GLOBALS['ec2Client']->getIterator('describeInstances',array(
                        'Filters' => array(

                                                'Name' => 'instance-state-name',
                                                'Values' => array('running')



                foreach($iterator as $object){

                        echo $object['InstanceId'] . PHP_EOL;


echo print_r(allInstances(),true);

... and we get our instances back. Sweet!

pi@raspberrypi ~/phpscripts/greenmode $ /usr/bin/php sdktest.php



Unknown said...


Unknown said...

hi it was really a customized way of Mounting The AWS on Raspberry pi and it will really take the automation in the physical world through Raspberry pi and can be a switch to AI or IOT based innovation

really appreciate the work

By profession i m an instructor of AWS and i m always in Search of these kind of innovative blogs

so let me share you my Work on AWS :-

A little about Me

My photo
My name is Mitch Beaumont and I've been a technology professional since 1999. I began my career working as a desk-side support engineer for a medical devices company in a small town in the middle of England (Ashby De La Zouch). I then joined IBM Global Services where I began specialising in customer projects which were based on and around Citrix technologies. Following a couple of very enjoyable years with IBM I relocated to London to work as a system operations engineer for a large law firm where I responsible for the day to day operations and development of the firms global Citrix infrastructure. In 2006 I was offered a position in Sydney, Australia. Since then I've had the privilege of working for and with a number of companies in various technology roles including as a Solutions Architect and Technical team leader.