微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在AWS的cloudformation模板中无法识别“事件:”一词

如何解决在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,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,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,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,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

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

解决方法

Runtime部分下检查您的Globals,在Python3.6之间有一个空格。

尝试一下

Globals:
  Function:
    MemorySize: 128
    Runtime: Python3.6
    Timeout: 5
,

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

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"]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。