我对CloudFormation中的引用或变量的工作原理非常不清楚。
目前,我在serverless.yml中的iAmRole如下:
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
# Restrict our IAM role permissions to
# the specific table for the stage
Resource:
- "Fn::GetAtt": [ ReportsTable, Arn ]
ReportsTable 是在另一个文件中创建的表,它看起来像这样:
Resources:
ReportsTable:
Type: AWS::DynamoDB::Table
Properties:
...
LocalSecondaryIndexes:
- IndexName: typeId-accessToken-index
KeySchema:
- AttributeName: typeId
KeyType: HASH
...etc
我知道Fn::GetAtt数组中的第二个值是引用属性名,但我不明白Arn是从哪里来的。它看起来像一个变量,但它在任何地方都没有定义。
最终,我需要添加另一个Effect、Action、Resource块,引用我创建的本地二级索引,但我不知道从哪里开始。
编辑:看起来Arn来自于dynamoDB表返回的值(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html)
编辑2:好吧,现在我有了格式为arn:aws:dynamodb:region:account-id:table/table-name/index/*
的值,参考permissions reference docs,正在测试。