Welcome Guest, Not a member yet? Register   Sign In
aws sdk for php 2 integration with codeigniter
#1

[eluser]Unknown[/eluser]
Hello. I am having some problems with getting the aws sdk2 for php to work in my codeigniter installation. Basically, I dont know where to begin! The old aws sdk was pretty simple to integrate, you had the main sdk class and the config file, and there were plenty of resources on google for implementing it. But I cant find anything similar for this new sdk and it looks more complicated than the first sdk. Can anyone help me get started or point me to a resource I may have missed? The features of the sdk I am particularly interested in are dynamodb and s3. Thanks.
#2

[eluser]solidrockit[/eluser]
Check these
http://docs.aws.amazon.com/aws-sdk-php-2...ation.html
http://yalamber.com/2013/01/aws-sdk-php-...plication/ (see how they are explained two methods composer.json and directly aws.phar in the first comment)
#3

[eluser]scriptigniter[/eluser]
[quote author="vicse1784" date="1364046607"]Hello. I am having some problems with getting the aws sdk2 for php to work in my codeigniter installation. Basically, I dont know where to begin! The old aws sdk was pretty simple to integrate, you had the main sdk class and the config file, and there were plenty of resources on google for implementing it. But I cant find anything similar for this new sdk and it looks more complicated than the first sdk. Can anyone help me get started or point me to a resource I may have missed? The features of the sdk I am particularly interested in are dynamodb and s3. Thanks.[/quote]


If you are interested in only to use S3 then you can find this library very useful http://codecanyon.net/item/codeigniter-a...ry/4993914
Using this library you can easily use without leaving the comfort of Codeigniter. Please share your experience too after using this.
#4

[eluser]Greg767[/eluser]
Hi,

Please help me with this. I don't find any info on how to use AWS sdk with codeigniter. I want to use the SNS. All links posted here refer to the old AWS sdk.

Thanks a lot
Greg
#5

[eluser]Greg767[/eluser]
So, for anyone interested, here is how I did it (on Win8 and WAMP):
Install Composer for windows.
For a successful installation you need to enable php-openssl and php-curl in WAMP. This need to be enabled also in wamp/bin/php/php.ini and not only on WAMP user interface. Also I chose to install composer with the Explorer plugin, this way you can have Composer in the contextual menu in explorer (right-click).

In the project root directory (I use netbeans) create a composer.json and put this as content:
Code:
{
    "require": {
        "aws/aws-sdk-php": "2.*"
}
}

Right-click in the project's root folder (where the json is) and choose Composer Install from the right-click menu.
This will install everything.



In the root folder in index.php add this line:
Code:
require_once './vendor/autoload.php';

In application/config create aws_sdk.php with the following content:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['aws_access_key']="PUT_HERE_YOUR_KEY";
$config['aws_secret_key']="PUT_HERE_YOUR_SECRET_KEY";

In application/libraries create Aws_sdk folder.

In application/libraries/Aws_sdk create Aws_sdk.php with the following:

Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

use Aws\Sns\SnsClient; //here you define what module(s) you want to use

class Aws_sdk {

    public $snsClient;
    public $ci;

    public function __construct() {
        $this->ci = & get_instance();
        $this->ci->load->config('aws_sdk');
        $this->snsClient = SnsClient::factory(array(
                    'key' => $this->ci->config->item('aws_access_key'),
                    'secret' => $this->ci->config->item('aws_secret_key'),
                    'region' => "us-west-2"
        )); //Change this to instantiate the module you want. Look at the documentation to find out what parameters you need.
    }

    public function __call($name, $arguments = null) {
        if (!property_exists($this, $name)) {
            return call_user_func_array(array($this->snsClient, $name), $arguments);
        } //Change this accordingly too
    }

//Write your methods to call AWS functionality
    public function SendPushNotification($message, $target)
    {
        $result = $this->snsClient->publish(array(
            'TargetArn' => $target,
            'Message' => $message
        ));
    }
}

Thats all. It worked for me.

Greg

PS.: Original source of this solution: https://github.com/fcosrno/aws-sdk-php-codeigniter




Theme © iAndrew 2016 - Forum software by © MyBB