serverless.template 中的 aws VS2017 无服务器应用程序语法,用于向 s3 通知添加过滤器

aws VS2017 serverless app syntax in serverless.template to add filter to s3 notification

我使用带有 "Simple S3 Function" 蓝图的 AWS 无服务器应用程序模板创建了一个 VS2017 C# 应用程序。 CloudFormation serverless.template 文件包含我的处理程序函数的规范以及响应 "s3.ObjectCreated:*" 事件的事件规范。我正在尝试向该事件规范添加过滤器规范,以仅响应带有 "Source/" 前缀的事件。这是我的代码:

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Transform" : "AWS::Serverless-2016-10-31",
  "Description" : "Template that creates a S3 bucket and a Lambda function that will be invoked when new objects are upload to the bucket.",
  "Parameters" : {
    "BucketName" : {
        "Type" : "String",
        "Description" : "Name of S3 bucket to be created. The Lambda function will be invoked when new objects are upload to the bucket. If left blank a name will be generated.",
        "MinLength" : "0"
    }
  },

  "Conditions" : {
    "BucketNameGenerated" : {"Fn::Equals" : [{"Ref" : "BucketName"}, ""]}
  },


  "Resources" : {

    "Bucket" : {
        "Type" : "AWS::S3::Bucket",
        "Properties" : {
            "BucketName" : { "Fn::If" : ["BucketNameGenerated", {"Ref" : "AWS::NoValue" }, { "Ref" : "BucketName" } ] }
        }
    },

    "S3Function" : {
      "Type" : "AWS::Serverless::Function",
      "Properties": {
        "Handler": "DCATInventory::DCATInventory.Function::FunctionHandler",
        "Runtime": "dotnetcore2.0",
        "CodeUri": "",
        "Description": "Default function",
        "MemorySize": 256,
        "Timeout": 30,
        "Role": null,
        "Policies": [ "AWSLambdaFullAccess", "AmazonRekognitionReadOnlyAccess" ],
        "Events": {
            "NewImagesBucket" : {
                "Type" : "S3",
                "Properties" : {
                    "Bucket" : { "Ref" : "Bucket" },
                    "Events" : [
                        "s3:ObjectCreated:*"
                    ],
                    "Filter" : {
                        "S3Key" : {
                            "Rules" : [{
                                "Name" : "prefix", 
                                "Value": "Source/"
                            }]
                        }
                    }
                }
            }
        }
      }
    }
  },
  "Outputs" : {
    "Bucket" : {
        "Value" : {"Ref":"Bucket"},
        "Description" : "Bucket that will invoke the lambda function when new objects are created."
    }
  }
}

这是模板生成的默认代码,仅将过滤器规范添加到事件属性。我在第 48 行收到一条错误消息,指出 "Rules key is invalid for this object"。我已阅读文档并用谷歌搜索,这似乎是正确的语法。我在这里指定了错误吗?提前致谢。

事实证明我上面显示的语法是正确的,即使 Visual Studio 报告错误。即使出现此错误,我还是决定尝试将应用程序发布到 AWS。我预计我会从 CloudFront 收到错误,但它已成功发布。 S3 事件确实发布并包含带有 "Source/" 前缀的过滤规则。