确保使用正确的模板格式和语法,例如:
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: nodejs12.x CodeUri: . Description: A Hello World Lambda function MemorySize: 128 Timeout: 3 Environment: Variables: MESSAGE: "Hello World!"
使用 AWS CLI 命令验证模板并创建堆栈,例如:
$ aws cloudformation validate-template --template-body file://template.yaml
$ aws cloudformation create-stack --stack-name HelloWorld --template-body file://template.yaml
注意:确保 aws cli 版本正确并设置了正确的 AWS 凭证。