AWS Cloudformation cfn-init 未安装包

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

我试图让一个简单的AWS Cloudformation。cfn-init 脚本工作,但没有任何成功。脚本如下所示。当我登录到创建的实例时,httpd甚至没有安装。我正在 us-east-1 中创建一个 AWS Linux2 实例。

Resources:
  ...
  Ec2Instance:
    Type: AWS::EC2::Instance
    Metadata: 
      AWS::CloudFormation::Init: 
        config: 
          packages: 
            yum:
              httpd: []
          files:
            /var/www/html/index.html:
              content: !Sub |
                <html><body>Hello, World</body></html>
          services: 
            sysvinit:
              httpd:
                enabled: true
                ensureRunning: true
    Properties:
      InstanceType: t2.micro
      ImageId: ami-0323c3dd2da7fb37d
      KeyName: KeyPair
      SecurityGroupIds:
        - !Ref InstanceSecurityGroup
      UserData:
        Fn::Base64:                                
          !Sub |
            #!/bin/bash -xe
            yum update -y aws-cfn-bootstrap
            /opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource Ec2Instance --region ${AWS::Region}
amazon-web-services yaml amazon-cloudformation
1个回答
0
投票

我部署了你的模板,可以 确认无误. httpdindex.html 的安装和部署符合预期。

一定有其他事情发生。例如,部署到一个没有互联网的私有子网。在这种情况下,httpd需要被安装。或者像 @Christian 提到的,修改现有的实例。

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