我使用sam将dynamodb表定义为这样:
#DynamoTables
DevicesTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: devices
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
-
AttributeName: "customerId"
AttributeType: "S"
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
-
AttributeName: "customerId"
KeyType: "RANGE"
GlobalSecondaryIndexes:
-
IndexName: "customers"
KeySchema:
-
AttributeName: "customerId"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"我能够使用带有sam中定义的Properties: Policies: AmazonDynamoDBFullAccess的lambda函数访问表,并在node中使用TableName: 'devices'定义put参数。但是,当我试图通过将索引定义为这样的查询来查询索引时:
params = {
TableName: 'devices',
IndexName: 'customers'
// ...
}我得到一个错误,说明lambda函数没有访问该索引的权限:
用户: arn:aws:sts:::assumed-role/CodeStarWorker-Lambda/awscodestar-lambda-DeviceFunction未被授权执行:dynamodb:查询资源:TABLEURL/设备/索引/客户
有人知道我可以授予这个访问权或者绕过这个方法来查询索引吗?
更新:我不认为AmazonDynamoDBFullAccess策略会影响到任何事情,当我从template.yml中删除它时,我仍然能够放到表中,仍然无法查询索引。我必须手动添加角色吗?
发布于 2019-06-03 21:06:01
您的lambda可以访问TABLEURL/设备,但不能访问TABLEURL/设备/index/customers。
以下是aws文档中的一个示例,说明如何允许访问数据库的所有索引。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AccessAllIndexesOnBooks",
"Effect": "Allow",
"Action": [
"dynamodb:*"
],
"Resource": [
"arn:aws:dynamodb:us-west-2:123456789012:table/Books",
"arn:aws:dynamodb:us-west-2:123456789012:table/Books/index/*"
]
}
]
}https://stackoverflow.com/questions/53198712
复制相似问题