有没有办法使用Laravel AWS SDK设置DynamoDB Local? [英] Is there a way to set up DynamoDB Local with the Laravel AWS SDK?

查看:130
本文介绍了有没有办法使用Laravel AWS SDK设置DynamoDB Local?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在当前的laravel项目中启动DynamoDB Local并运行时遇到了问题.

I have run into problems trying to get DynamoDB Local up and running with my current laravel project.

Laravel AWS开发工具包允许在.env文件中设置一些密钥来更改密钥/秘密/区域,但是似乎不支持更改端点,因此使用DynamoDB Local(密钥选项位于自述文件中: https://github.com/aws/aws-sdk- php-laravel ).

The Laravel AWS SDK allows for a few keys to be set in the .env file to change the key/secret/region, but does not seem to support changing the endpoint, and that would be needed to use DynamoDB Local (key options are in the readme here: https://github.com/aws/aws-sdk-php-laravel).

常规PHP SDK的文档似乎关于如何设置Dynamo DB Local的简单明了:

The documentation for the regular PHP SDK seems pretty straight-forward about how to set up Dynamo DB Local:

$client = DynamoDbClient::factory(array(
    'profile' => 'default',
    'region' => 'us-west-2', #replace with your desired region
    'endpoint' => 'http://localhost:8000'
));

使用Laravel AWS开发工具包,我无法直接访问DynamoDBClient,而不会破解大量生产DynamoDB连接所必需的东西.

With the Laravel AWS SDK I don't have direct access to the DynamoDBClient without hacking up a bunch of stuff that is necessary for the production DynamoDB connection.

例如,使用Laravel AWS开发工具包,可以通过以下方式访问DynamoDB:

For example with the Laravel AWS SDK the DynamoDB is accessed by something like:

$dynamoDB = AWS::get('DynamoDb');

我真的在寻找可以更改的环境变量之类的东西,以便可以在生产环境和本地环境之间轻松切换,但是找不到.

I am really looking for something like an environment variable that can be changed so that I can easily switch between production and my local, but I can't find it.

是否有使用Laravel AWS开发工具包设置DynamoDB Local的简便方法?

Is there any easy way to set up DynamoDB Local with the Laravel AWS SDK?

推荐答案

我最终使它起作用的方法是创建自己的环境变量,然后检查在获取DynamoDBClient时是否设置了该变量. >

The way I ended up getting this to work was to create my own environment variable and then check to see if it was set when I got the DynamoDBClient.

AWS::get('DynamoDb')

上面的代码返回一个DynamoDBClient,它会自动使用您的AWS配置.

The above returns a DynamoDBClient that is automatically using your AWS configuration.

因此,我检查了env变量,如果设置了env变量,则返回具有本地配置的DynamoDBClient.我不得不使用Aws DynamoDBClient类:

So, I did a check for the env variable, and return a DynamoDBClient with the local configuration if the env variable is set. I had to use the Aws DynamoDBClient class:

use Aws\DynamoDb\DynamoDbClient;

然后我做了:

if( env("DYNAMODB_LOCAL")) {
    $this->client = DynamoDbClient::factory(array(
        'key' => 'YOUR_KEY', // Doesn't actually matter what it is since it won't be verified
        'secret' => 'YOUR_SECRET', // Doesn't actually matter what it is since it won't be verified
        'profile' => 'default',
        'region' => 'us-west-2', #replace with your desired region
        'endpoint' => 'http://localhost:8000' // Replace if your local endpoint is different than default
    ));
}
else {
    $this->client = AWS::get('DynamoDb');
}

如果Laravel AWS开发工具包附带了某种针对DynamoDB Local的简单环境配置,那将是很好的选择,但这似乎对我有用.

It would have been nice if the Laravel AWS SDK came with some kind of easy environment configuration for DynamoDB Local, but this seems to work for my uses.

这篇关于有没有办法使用Laravel AWS SDK设置DynamoDB Local?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆