DynamoDB的关键元素与架构不相符合
时间:2024-02-15
浏览:265
作者:佚名
最近发现不少小伙伴都对Golang很感兴趣,所以今天继续给大家介绍Golang相关的知识,本文《DynamoDB的关键元素与架构不相符合》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~
问题内容
我在这里定义了 terraform 中的 dynamodb 表:
name = "component_table"
partition_key = "name"
partition_key_type = "s"
sort_key = "version"
billing_mode = "pay_per_request"
environment = "testing"
aws_region = "eu-west-1"
restore_to_latest_time = true
point_in_time_recovery = true
extra_attributes = [
{
name = "version"
type = "s"
},
{
name = "team"
type = "s"
}
]
local_secondary_index = [
{
name = "teamsecondaryindex"
projection_type = "all"
range_key = "team"
}
]
我已经使用 aws 运算符 getitem 查询了它,出于测试目的,我将名称定义为 abc,但似乎无法查询 getitem 函数,因为它说
the provided key element does not match the schema error
我运行的函数是这样的:
func (m *Manager) ComponentGetByName(ctx context.Context, name string) (componentModel.Component, error) {
getItemInput := &awsDDB.GetItemInput{
TableName: &m.cfg.tableName,
Key: map[string]types.AttributeValue{
"name": &types.AttributeValueMemberS{
Value: name,
},
},
}
getItemOutput, err := m.Client.GetItem(ctx, getItemInput)
return getItemOutput
}
为了保密,我省略了一些细节,例如将 getitemoutput 转换为组件模型。我想知道为什么会发生这种情况以及如何解决?开放讨论。谢谢!
正确答案
问题是您尝试仅使用分区键值执行 GetItem。要执行 GetItem,您必须提供完整的主键,即分区和排序键值。在您的情况下,需要 name 和 version。
如果您只知道分区键,则必须执行Query操作。
您必须提供分区键属性的名称以及该属性的单个值。查询返回具有该分区键值的所有项目
今天关于《DynamoDB的关键元素与架构不相符合》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
