我正在使用SAM模板来创建我的无服务器应用程序。
使用资源属性下的标记Policies
,我可以添加如下标准策略:
Resources:
QueryFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: query/
Handler: app.lambda_handler
Policies:
- AmazonDynamoDBFullAccess
- AWSLambdaVPCAccessExecutionRole
Runtime: python3.7
问题是我需要附加内联策略才能仅访问特定的 DynamoDB 表。
如何将此内联策略放入模板中?
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "dynamo_db_table_endpoint"
}
]
}
谢谢
试试这个:
QueryFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: query/
Handler: app.lambda_handler
Policies:
- AmazonDynamoDBFullAccess
- AWSLambdaVPCAccessExecutionRole
- Version: '2012-10-17' # Policy Document
Statement:
- Effect: Allow
Action:
- dynamodb:*
Resource: 'arn:aws:dynamodb:*:*:table/dynamo_db_table_endpoint'
Runtime: python3.7
Amazon DynamoDB:允许访问特定表
如果要将表名作为参数更改Resource: 'arn:aws:dynamodb:*:*:table/dynamo_db_table_endpoint'
传递给Resource: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}'
希望这有帮助