Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example of DynamoDB #23

Closed
qyqyqy03 opened this issue Jul 4, 2016 · 28 comments
Closed

An example of DynamoDB #23

qyqyqy03 opened this issue Jul 4, 2016 · 28 comments

Comments

@qyqyqy03
Copy link

qyqyqy03 commented Jul 4, 2016

hi, i am a new laravel and aws user
i had finished the steps before [Usages] in documentation
but i cant understand how to use it
Can anyone give an example of what code should apply and where?

Thanks!

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

Hello, thanks for reminding me to update the docs. Here are the steps:

  1. Configure your dynamodb credentials in config/services.php
  2. Create your model class as usual
  3. Extend this class with BaoPham\DynamoDb\DynamoDbModel
  4. Set your $fillable property
  5. Use the Eloquent syntax as usual

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

hi, thanks for your reply
but I still have difficult to connect dynamodb

Do i correct below for the model class?
app/Product.php

app/Http/Controllers/ProductController.php

with('products', $products); } }

such as I have a "products" table

  • id
  • name

but here have some errors

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

what are the errors?

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

FatalErrorException in Product.php line 8:
Class 'App\BaoPham\DynamoDb\DynamoDbModel' not found

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

You have the namespace wrong, put \ in front of BaoPham

class Product extends \BaoPham\DynamoDb\DynamoDbModel

If you use an IDE (PhpStorm), it'd help with error like this.

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

Thank you, it have good changing, but have the below error

DynamoDbException in WrappedHttpHandler.php line 192:
Error executing "Scan" on "https://dynamodb.us_east_1.amazonaws.com"; AWS HTTP error: cURL error 6: Could not resolve host: dynamodb.us_east_1.amazonaws.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

Please check your services.php again and see if you have put all the correct info. Good way to check also is to use artisan tink and call config('services.dynamodb')

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

services.php

    'dynamodb' => [
        'key' => env('DYNAMODB_KEY'),
        'secret' => env('DYNAMODB_SECRET'),
        'region' => env('DYNAMODB_REGION'),
        'local_endpoint' => env('DYNAMODB_LOCAL_ENDPOINT'), // see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html
        'local' => env('DYNAMODB_LOCAL'), // true or false? should use dynamodb_local or not?
    ],

and i added the code in .env

DYNAMODB_KEY=XXX...
DYNAMODB_SECRET=XXX...
DYNAMODB_REGION=US_EAST_1

and the checking result
is
=> [
"key" => "XXX...",
"secret" => "XXX...",

 "region" => "US_EAST_1",
 "local_endpoint" => null,
 "local" => null,

]

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

Change to us-east-1 for the region

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

error is the same
... "https://dynamodb.us-east-1.amazonaws.com" ...
only us_east_1 to us-east-1 changed

@baopham
Copy link
Owner

baopham commented Jul 6, 2016

are you certain that it is the correct region?

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

yes, i am using "US East (N. Virginia)" which displayed in the top-right corner on aws console
and it works with the no framework php:
'region' => Aws\Common\Enum\Region::US_EAST_1,

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 6, 2016

Or is that is a feasible way to give me a template repository which just let me to fill in the KEY and SECRET and table name? Then i can connect with dynamodb and display the items on my table.

@baopham
Copy link
Owner

baopham commented Jul 7, 2016

It seems more like a network issue actually.

Why don't you put up a quick repo of what you have so far and I can take a look.

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 7, 2016

It is a good idea!
https://drive.google.com/open?id=0B7a_eGs6V1ToaHFyX0VYMVRHU00
The project I use "products" as my testing
Thanks!

@baopham
Copy link
Owner

baopham commented Jul 8, 2016

I will take a look in the weekend.

@qyqyqy03
Copy link
Author

Thank you!

@baopham
Copy link
Owner

baopham commented Jul 11, 2016

I created a table products under region us-east-1 and it's working fine for me. Check your network if somehow it is blocked.

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 11, 2016

hi
I just added my key and secret in .env
then have a table called "products" like this

https://drive.google.com/file/d/0B7a_eGs6V1TobVdtMFZjNnl0XzQ/view?usp=sharing

with itemid and itemAddress attribute

However, when I go to http://localhost:8000/product
I still got the error of

"Error executing "Scan" on "https://dynamodb.us-east-1.amazonaws.com"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)"

@baopham
Copy link
Owner

baopham commented Jul 11, 2016

That sounds more like a different problem. Google will help. For example, http://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate

By the way,
Is itemid your primary key? if so, please set it in your Product class:

protected $primaryKey = 'itemid';

by default your primary key is id

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 11, 2016

am i right?
https://drive.google.com/open?id=0B7a_eGs6V1ToUjhUZEdkZEdnTzg

and this in Product.php

@baopham
Copy link
Owner

baopham commented Jul 11, 2016

Yes, but you should use string for primary key. Dynamodb does not support incrementing ID. You have to set the ID yourself. But this is a separate thing I wanted to point out. You should google for the error that you're getting

@qyqyqy03
Copy link
Author

thanks!
why you are working fine but I cant for the same repo with same changes?

@baopham
Copy link
Owner

baopham commented Jul 11, 2016

My local server has ssl cert setup correctly?

@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 12, 2016

I finally got the item data but in an error page
but it is a great step for me
Thank you so much!

@baopham
Copy link
Owner

baopham commented Jul 14, 2016

great

@baopham baopham closed this as completed Jul 14, 2016
@qyqyqy03
Copy link
Author

qyqyqy03 commented Jul 18, 2016

hi
I have a problem with upload photo with S3

In the ..blade.php
{!!Form::file('image')!!}

In the Controller

public function store(Request $request)
    {
..........
$imageFileName = "123.png";
$s3 = \Storage::disk('s3');
        $filePath = '/mybucket/' . $imageFileName;
        $s3->put($filePath, file_get_contents($request->file('image')), 'public');
............
}

Why I have an error on

file_get_contents(): Filename cannot be empty

@baopham
Copy link
Owner

baopham commented Jul 18, 2016

This has nothing to do with this library. Please use Stackoverflow for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants