VS 2019 AWS Serverless.Template 解析错误

问题描述

下午, 尝试使用 aws 工具包和 servless.template 创建一个按计划触发并将数据插入 sqs 存储桶的 lambda。除了“事件”行之外,一切都很好。我收到一条错误消息,显示“第 24 行解析错误”。我已经检查,仔细检查并验证了波浪线支架的位置,但没有通过。根据 aws 文档,我应该能够在 lambda 定义中建立事件。

非常感谢任何帮助!这是我的代码。参数化,因为应用将通过 azure 部署在多个环境中。

{
"AWstemplateFormatVersion": "2010-09-09","Transform": "AWS::Serverless-2016-10-31","Description": "An AWS Serverless Application.","Parameters":{
    "AwsRole" : { "Description" : "Role for lambda expression","Type": "String"},"SecurityGroup" : { "Description" : "List of secuirty group ids,comma delimited","Type" : "List<String>" },"subnets" : { "Description" : "List of subnet ids,"Schedule" : {"Description" : "Cron schedule","Type" : "String"}
  },"Resources": {
    "PopulateQueue": {
      "Type": "AWS::Serverless::Function","Properties": {
        "Handler": "SendToQueue::SendToQueue.PopulateSqs::RunPopulate","Runtime": "dotnetcore3.1","CodeUri": "","MemorySize": 256,"Role" : {"Ref" : "AwsRole"},"VpcConfig" : {           
            "SecurityGroupIds" : { "Ref" : "SecurityGroup" },"subnetIds" : { "Ref" : "subnets"}
         }   
error here--->"Events": {
          "Trigger":{
            "Type": "Schedule"
            "Properties" : {
                "Schedule" : { "Ref" : "Schedule" },"Name" : "PopulateSqsSchedule","Description" : "Schedule for sending items to sqs","Enabled" : false
            }
          }
            
        }
      }
    },"SendQueue": {
        "Type": "AWS::SQS::Queue","Properties": {
            "ContentBasedDeduplication": true,"MessageRetentionPeriod": 1200,"QueueName": "SendQueue"
        }
    }

    }
  }
}

解决方法

看起来在第 23 行你有一个错字 - 在 , 之后缺少 }。第 26 行也缺少 ,

通常使用 some online tool 验证您的 JSON 非常有用,它可以帮助您快速了解错误。