【问题标题】:Can't create_stack with CloudFormation with aws cli but can in the portal无法使用带有 aws cli 的 CloudFormation 创建堆栈,但可以在门户中
【发布时间】:2023-02-03 15:43:54
【问题描述】:

我有一个有效的 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 的吗?关于我的命令行调用?一些环境变量?

【问题讨论】:

  • 您是否有任何未能稳定的 EC2 日志?
  • 如何访问 EC2 实例的日志?它在我的 ec2 仪表板中显示为已终止。当我尝试系统日志时,它显示为空
  • 您使用的是什么操作系统?什么是ami-01ec0fa63b2042232
  • 只是猜测,但是您用于从控制台登录/创建的用户与 aws CLI 用于命令行的用户之间是否存在权限差异?比如说,可以使用 AMI 或 KMS 的许可。

标签: amazon-web-services amazon-ec2 amazon-cloudformation


【解决方案1】:

这可能与创建实例所花费的时间长短有关,但是您的“用户数据”脚本似乎很简单,很难想象是这种情况。 AWS 文档指出此错误与 the resource creation time exceeding the CloudFormation timeout 有关:

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

我要快速检查的一件事是,您的用户数据脚本中的 -e option to bash 不会导致它以某种方式失败从而阻碍实例创建。

根据 AWS 的建议,另一种可能的解决方案是确保您的 CloudFormation 堆栈是 provided a service role when it is created。这将允许它创建超出使用创建用户的 IAM 权限时强加的超时的基础设施。

【讨论】:

    猜你喜欢
    • 2018-12-17
    • 2019-12-07
    • 2019-12-13
    • 2016-08-13
    • 2018-10-01
    • 2018-10-27
    • 2019-03-23
    • 2017-02-06
    • 2021-06-29
    相关资源
    最近更新 更多