如何在 serverless.yml 中引用二级索引?

col*_*ars 3 aws-cloudformation serverless-framework aws-serverless

我不太清楚引用或变量如何与 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 ]
Run Code Online (Sandbox Code Playgroud)

ReportsTable 是在另一个文件中创建的表,如下所示:

Resources:
  ReportsTable:
    Type: AWS::DynamoDB::Table
    Properties:
    ...
    LocalSecondaryIndexes:
        - IndexName: typeId-accessToken-index
          KeySchema:
          - AttributeName: typeId
            KeyType: HASH
            ...etc
Run Code Online (Sandbox Code Playgroud)

我知道 Fn::GetAtt 数组中的第二个值引用了一个属性名,但我不明白 Arn 来自哪里。它看起来像一个变量,但它没有在任何地方定义。

最终,我需要添加另一个引用我创建的本地二级索引的 Effect、Action、Resource 块,但我不知道从哪里开始。

编辑:看起来 Arn 来自 dynamoDB 表返回值(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html

EDIT2:好了,所以我现在的格式arn:aws:dynamodb:region:account-id:table/table-name/index/*权限参考文档,现在测试。

小智 5

您可以使用 Cloudformation 内在函数Sub来创建索引 arn

!Sub '${ReportsTable.Arn}/index/*'
Run Code Online (Sandbox Code Playgroud)