【问题标题】:How to connect AWS DynamoDb directly with dart如何将 AWS DynamoDb 直接与 dart 连接
【发布时间】:2022-11-11 15:56:19
【问题描述】:
我正在开发一个 Flutter 中的消息传递应用程序,所有消息都存储在 AWS DynamoDB 中。我没有找到任何关于直接支持 DynamoDB 和 Dart 的文档。所以我首先将 DB 连接到 NodeJS 并使用来自 Flutter 应用程序的 http req 来获取消息。但它的可靠性并不高。只有我能找到一种直接连接它的方法,我才能让应用程序更快。如果那里有人知道这种方法,请帮忙。
【问题讨论】:
标签:
amazon-web-services
flutter
dart
amazon-dynamodb
【解决方案2】:
您也许可以尝试非 AWS 提供的 SDK,例如 one。它包括一个 DynamoDB 客户端。我以前没用过,所以不能保证。
【解决方案3】:
正如理查德所说,https://pub.dev/packages/aws_dynamodb_api 是一个很好的解决方案。
我在 dart 中将 DynamoDB 集成为其他语言:
static var client = DynamoDB(region: 'eu-west-1',
endpointUrl: "http://localhost:8000",
credentials: AwsClientCredentials(accessKey: "dummy", secretKey: "dummy"));
static Future<bool> init() async {
var attributeDefinitions = <AttributeDefinition>[
AttributeDefinition(attributeName: "user_id", attributeType: ScalarAttributeType.n)
];
var keySchema = <KeySchemaElement>[
KeySchemaElement(attributeName: "user_id", keyType: KeyType.hash)
];
var throughput = ProvisionedThroughput(readCapacityUnits: 10, writeCapacityUnits: 10);
try
{
var response = await client.createTable(attributeDefinitions: attributeDefinitions, keySchema: keySchema, provisionedThroughput: throughput, tableName: "Users");
print("Created table ${response.tableDescription!.tableName}");
return true;
} catch(e)
{
print("Error: $e");
return false;
}