craftcms / yii2-dynamodb

Yii2 implementation of a queue and cache driver for DynamoDB
MIT License
5 stars 1 forks source link

Can't push data to dynamodb #4

Closed srakl closed 2 years ago

srakl commented 3 years ago

Description

I can't seem to get sessions to store in dynamodb. my key and secret are correct and i can connect using nosql workbench but nothing is pushed from local to dynamodb. What am i doing wrong here? Thanks

Steps to reproduce

  1. This is in my main.php
'session' => [
            'class' => DynamoDbSession::class,
            'table' => 'sessions',
            'tableIdAttribute' => 'id', // optional: defaults to id
            'tableDataAttribute' => 'data', // optional: defaults to data
            //'endpoint' => 'https://localhost/yii2/frontend/web/', // optional: used for local or when using DAX
            'key' => 'XXXXXXXXXXX', // optional: defaults to AWS_ACCESS_KEY_ID env var
            'secret' => 'XXXXXXXXXXXXXX', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
            'region' => 'ap-southeast-1', // optional: defaults to AWS_REGION env var
        ],
  1. Created dynamodb table like this

aws dynamodb create-table --table-name=sessions --attribute-definitions=AttributeName=id,AttributeType=S --key-schema=AttributeName=id,KeyType=HASH --billing-mode=PAY_PER_REQUEST { "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], "TableName": "sessions", "KeySchema": [ { "AttributeName": "id", "KeyType": "HASH" } ], "TableStatus": "CREATING", "CreationDateTime": "2021-07-28T12:47:16.767000+08:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 0, "WriteCapacityUnits": 0 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:ap-southeast-1:182823296337:table/sessions", "TableId": "d4757d4a-ccad-4aba-87c1-XXXXXXXXXXXX", "BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" } } }


3. when i set a session nothing show in db

$session = Yii::$app->session;

$session->set('name', 'stack');



### Additional info

- Craft version:
- PHP version: 8.0.8
- Database driver & version:
- Plugins & versions: 1.0
jasonmccallister commented 3 years ago

Hi @srakl! Can you verify the instance has permissions to dynamodb?

srakl commented 3 years ago

@jasonmccallister Sorry new to dynamodb and Yii2,

but I think i did.

I went here https://console.aws.amazon.com/iamv2/home?#/roles and created a role

  1. Aws Service -> EC2 -> Next: permission
  2. selected AmazonDynamoDBFullAccess and created role

is there a different role i have to make for localhost?

srakl commented 3 years ago

any help on this? thanks

jasonmccallister commented 3 years ago

@srakl what you use on local host depends on the AWS CLI and what you are using for local development. The best approach is to use environment variables with an IAM dedicated to that specific role for accessing DynamoDB.

jasonmccallister commented 2 years ago

Closing this out. Let us know if there are any other issues