gpt4 book ai didi

amazon-web-services - 将内联策略添加到 aws SAM 模板

转载 作者:行者123 更新时间:2023-12-04 14:45:37 25 4
gpt4 key购买 nike

我正在使用 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: Allows Access to a Specific Table

如果您想通过您的 表名作为参数更改 Resource: 'arn:aws:dynamodb:*:*:table/dynamo_db_table_endpoint'Resource: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}'
希望这可以帮助

关于amazon-web-services - 将内联策略添加到 aws SAM 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59249717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com