首页 > 解决方案 > AWS 的 cloudformation 模板中无法识别术语“事件:”

问题描述

我正在尝试使用 SAM 无服务器框架。一直在关注一个教程。我遵循的步骤

  1. 创建了一个 SAM 模板。
  2. 将SAM模板转换成云形成模板并存储在S3中
  3. 尝试部署从转换生成的云形成模板。

以下是转换后的云形成模板:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Demo For SAM !!!
Globals:
  Function:
    MemorySize: 128
    Runtime: Python 3.6
    Timeout: 5
Resources:
  display:
    Type: AWS::Serverless::Function
    Properties:
      Handler: display.lambda_handler
      Events:
        GetLogs:
          Type: Api
          Properties:
            Path: /call
            Method: get
      CodeUri: s3://sumanth-sam/debb239335f6dcf3f3f146367295b556
  add:
    Type: AWS::Serverless::Function
    Properties:
      Handler: add.lambda_handler
      Events:
        Add:
          Type: Api
          Properties:
            Path: /add
            Method: post
      CodeUri: s3://sumanth-sam/debb239335f6dcf3f3f146367295b556

云形成堆栈将因以下错误而回滚。

Events:
Events: : The term 'Events:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was  
included, verify that the path is correct and try again.
At line:1 char:1
+ Events:
+ ~~~~~~~
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\asus\OneDrive\Desktop\SAM\sam_demo>         GetLogs:
GetLogs: : The term 'GetLogs:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path    
was included, verify that the path is correct and try again.
At line:1 char:9
+         GetLogs:
+         ~~~~~~~~
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\asus\OneDrive\Desktop\SAM\sam_demo>           Type: Api
Type: : The term 'Type:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was      
included, verify that the path is correct and try again.
At line:1 char:11
+           Type: Api
+           ~~~~~
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\asus\OneDrive\Desktop\SAM\sam_demo>           Properties:
Properties: : The term 'Properties:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a   
path was included, verify that the path is correct and try again.
At line:1 char:11
+           Properties:
+           ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Properties::String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\asus\OneDrive\Desktop\SAM\sam_demo>             Path: /call
Path: : The term 'Path:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At line:1 char:13
+             Path: /call
+             ~~~~~
    + CategoryInfo          : ObjectNotFound: (Path::String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我觉得问题可能出在模板的结构上(无法查明)。或者我可能会使用一些过时的方法。谁能帮我解决这个问题。

标签: amazon-web-servicesamazon-cloudformationaws-serverless

解决方案


建议在 VSCode 中尝试CloudFormation Linter在创作模板时内联查看其中一些错误:

E3030 You must specify a valid value for Runtime (Python 3.6).
Valid values are ["dotnetcore1.0", "dotnetcore2.0", "dotnetcore2.1", "dotnetcore3.1", "go1.x", "java8", "java8.al2", "java11", "nodejs", "nodejs4.3-edge", "nodejs4.3", "nodejs6.10", "nodejs8.10", "nodejs10.x", "nodejs12.x", "provided", "provided.al2", "python2.7", "python3.6", "python3.7", "python3.8", "ruby2.5", "ruby2.7"]

推荐阅读