无法通过 AWS cli 使用 CloudFormation 创建堆栈,但可以在门户中

问题描述 投票:0回答:2

我有一个可用的 cloudFormation yaml 模板。我知道它的工作原理,因为当我进入 aws 门户并通过单击创建堆栈时,就会创建堆栈。

但是,当我尝试在命令行上使用 cloudformation 时,会出现相同的 yaml 错误。

我不知道是什么导致了这个问题。有谁知道失败的原因是什么?

这是我调用的命令

aws cloudformation create-stack --stack-name ${stack_name} --template-body file://template.yaml --region ${region}

其中区域与我在 aws 门户中所在的区域相同。这是

template.yaml

---
AWSTemplateFormatVersion: 2010-09-09
Description: EC2 example instance
Resources:
  TestEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-01ec0fa63b2042232
      InstanceType: t3.medium
      SubnetId: subnet-*********
      UserData:
        Fn::Base64:
          !Sub |
          #!/bin/bash -xe
          echo "Running apt install -y git nfs-common binutils jq"
          apt-get install -y git nfs-common binutils jq

当我运行命令时,我看到堆栈开始在门户上创建,并发生以下事件

ec2-boilerplate ROLLBACK_COMPLETE   -
TestEC2Instance DELETE_COMPLETE -
TestEC2Instance DELETE_IN_PROGRESS  -
ec2-boilerplate ROLLBACK_IN_PROGRESS    The following resource(s) failed to create: [TestEC2Instance]. Rollback requested by user.
TestEC2Instance CREATE_FAILED   Instance i-0bdd3e7ee34edf1ef failed to stabilize. Current state: shutting-down. Reason: Client.InternalError: Client error on launch
TestEC2Instance CREATE_IN_PROGRESS  Resource creation Initiated
TestEC2Instance CREATE_IN_PROGRESS  -
ec2-boilerplate CREATE_IN_PROGRESS  User Initiated

与我的 template.yaml 有关吗?关于我的命令行调用?一些环境变量?

amazon-web-services amazon-ec2 aws-cloudformation
2个回答
0
投票

这可能与创建实例所需的时间长度有关,但您的“userdata”脚本似乎很简单,很难想象情况是这样。 AWS 文档指出此错误与 资源创建时间超过 CloudFormation 超时有关:

由于操作超出了 AWS 的限制,资源没有响应 CloudFormation 超时或 AWS 服务中断。为了 服务中断,检查相关AWS服务是否正在运行, 然后重试堆栈操作。

我要检查的一件事是,用户数据脚本中 bash

-e 选项不会导致它以某种方式失败,从而阻碍实例创建。

根据 AWS 建议,另一个可能的解决方案是确保您的 CloudFormation 堆栈在创建时提供服务角色。这将允许它在使用创建用户的 IAM 权限时施加的超时之外创建基础设施。


0
投票

我走错区了,但是都是一样的。

© www.soinside.com 2019 - 2024. All rights reserved.