【问题标题】:WebServerHost No default VPC for this userWebServerHost 此用户没有默认 VPC
【发布时间】:2018-09-01 02:59:35
【问题描述】:

我目前正在尝试从 Cloudformation 启动 Cloudwatch 和所有警报,我使用的是亚马逊的默认模板

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudwatchlogs.html

我现在很挣扎

 WebServerHost:
    Type: AWS::EC2::Instance
    Metadata:
      Comment: Install a simple PHP application
      AWS::CloudFormation::Init:
        config:
          packages:
            yum:
              httpd: []
              php: []
          files:
            "/tmp/cwlogs/apacheaccess.conf":
              content: !Sub |
                [general]
                state_file= /var/awslogs/agent-state
                [/var/log/httpd/access_log]
                file = /var/log/httpd/access_log
                log_group_name = ${WebServerLogGroup}
                log_stream_name = {instance_id}/apache.log
                datetime_format = %d/%b/%Y:%H:%M:%S
              mode: '000400'
              owner: apache
              group: apache
            "/var/www/html/index.php":
              content: !Sub |
                "<?php"
                "echo '<h1>AWS CloudFormation sample PHP application</h1>';"
                "?>"
              mode: '000644'
              owner: apache
              group: apache
            "/etc/cfn/cfn-hup.conf":
              content: !Sub |
                [main]
                stack= ${AWS::StackId}
                region=${AWS::Region}
              mode: "000400"
              owner: "root"
              group: "root"
            "/etc/cfn/hooks.d/cfn-auto-reloader.conf":
              content: !Sub |
                [cfn-auto-reloader-hook]
                triggers=post.update
                path=Resources.WebServerHost.Metadata.AWS::CloudFormation::Init
                action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerHost --region ${AWS::Region}
              mode: "000400"
              owner: "root"
              group: "root"
          services:
            sysvinit:
              httpd:
                enabled: 'true'
                ensureRunning: 'true'
              sendmail:
                enabled: 'false'
                ensureRunning: 'false'
    CreationPolicy:
      ResourceSignal:
        Timeout: PT5M
    Properties:
      ImageId:
        Fn::FindInMap:
        - RegionMap
        - Ref: AWS::Region
        - AMI
      KeyName:
        Ref: KeyName
      InstanceType: t1.micro
      SecurityGroupIds:
        - !Ref SecurityGroup
      IamInstanceProfile:
        Ref: LogRoleInstanceProfile
      UserData:
        "Fn::Base64":
          !Sub |
            #!/bin/bash -xe
            # Get the latest CloudFormation package
            yum update -y aws-cfn-bootstrap
            # Start cfn-init
            /opt/aws/bin/cfn-init -s ${AWS::StackId} -r WebServerHost --region ${AWS::Region} || error_exit 'Failed to run cfn-init'
            # Start up the cfn-hup daemon to listen for changes to the EC2 instance metadata
            /opt/aws/bin/cfn-hup || error_exit 'Failed to start cfn-hup'
            # Get the CloudWatch Logs agent
            wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
            # Install the CloudWatch Logs agent
            python awslogs-agent-setup.py -n -r ${AWS::Region} -c /tmp/cwlogs/apacheaccess.conf || error_exit 'Failed to run CloudWatch Logs agent setup'
            # All done so signal success
            /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource WebServerHost --region ${AWS::Region}

启动模板时出现此错误

    AWS::EC2::Instance  WebServerHost   No default VPC for this user

我在引用 VPCId 时解决了 WebServerSecurityGroup 的问题,问题是 WebServerHost 属性中不允许使用 VPCId。

有人知道如何将 VPC 提供给 WebServerHost 吗?

【问题讨论】:

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


    【解决方案1】:

    您需要使用SubnetId

    如果您使用的是 Amazon VPC,此属性指定 您要将实例启动到的子网

    【讨论】:

    • 不起作用 AWS::EC2::Instance WebServerHost 当前不支持请求的配置。请查看支持配置的文档。
    • 我猜,是因为InstanceType: t1.micro,它是上一代的实例类型,你能不能把它改成t2.micro
    猜你喜欢
    • 2015-12-14
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 2021-08-30
    相关资源
    最近更新 更多