将IAM策略文档对象列表用作AWS :: Serverless :: Function策略

时间:2018-06-29 17:08:05

标签: amazon-web-services aws-serverless aws-visual-studio-toolkit serverless-application-model

根据无服务器应用程序模型中AWS::Serverless::Function的{​​{3}},可以为资源的Policies属性指定IAM策略文档对象(PDO)的列表。

但是,当我尝试定义IAM PDO时,适用于Visual Studio的AWS工具包正在标记语法错误: documentation

这是我的Resources部分的完整示例:

"Resources": { "Example" : { "Type" : "AWS::Serverless::Function", "Properties": { "Handler": "Example::Example.Controllers.ExampleController::ExampleAction", "Runtime": "dotnetcore2.0", "CodeUri": "", "MemorySize": 256, "Timeout": 30, "Policies": [{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": "*", "Resource": "*" } }], "Events": { "PutResource": { "Type": "Api", "Properties": { "Path": "/{id}", "Method": "GET" } } } } } }

我出了什么问题吗,或者SAM或AWS Toolkit语法验证是否有问题?

3 个答案:

答案 0 :(得分:1)

我认为问题在于您的语法是它应该是一个语句数组,因为可以有如下所示的多个策略,

"Statement":[ 
              {
                "Effect": "Allow",
                "Action": "*",
                "Resource": "*"
              }
            ]

具有多个策略的示例如下,

"Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "dynamodb:Query"
              ],
              "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-songs-${dev}/*/*"
            },
            {
              "Effect": "Allow",
              "Action": [
                "dynamodb:GetItem"                  ],
              "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-users-${dev}"
            },

         ]

答案 1 :(得分:1)

我刚刚更新了VS CloudFormation模式。下次重新启动Visual Studio时,该问题将消失。

答案 2 :(得分:0)

该问题似乎是由Visual Studio和AWS Toolkit中的语法解析问题引起的。我在GitHub上提出了一个问题,您可以在这里跟踪它:https://github.com/aws/aws-sdk-net/issues/1001