gpt4 book ai didi

c# - serverless.template 中的 aws VS2017 无服务器应用程序语法用于将过滤器添加到 s3 通知

转载 作者:行者123 更新时间:2023-12-03 07:37:03 24 4
gpt4 key购买 nike

我使用 AWS 无服务器应用程序模板和“简单 S3 函数”蓝图创建了一个 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 行收到一条错误,指出“规则 key 对此对象无效”。我已阅读文档并用 google 搜索了此内容,这似乎是正确的语法。我在这里指定了错误吗?提前致谢。

最佳答案

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

关于c# - serverless.template 中的 aws VS2017 无服务器应用程序语法用于将过滤器添加到 s3 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50685445/

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