【发布时间】:2023-03-17 09:01:01
【问题描述】:
我非常不清楚引用或变量如何与 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 的来源。它看起来像一个变量,但它没有在任何地方定义。
最终我需要添加另一个引用我创建的本地二级索引的效果、动作、资源块,但我不知道从哪里开始。
编辑:看起来 Arn 来自 dynamoDB 表返回值 (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html)
Edit2:好的,所以我现在有了来自permissions reference docs 的arn:aws:dynamodb:region:account-id:table/table-name/index/* 格式,现在正在测试。
【问题讨论】:
-
arn:aws:dynamodb:region:account-id:table/table-name/index/* 是正确的参考。现在我需要弄清楚如何像上面所做的那样动态引用表名。以及如何在没有硬编码的情况下引用我的帐户 ID 和区域。
标签: amazon-cloudformation serverless-framework aws-serverless