【问题标题】:AutoScaling ec2 instance with cloudformation具有 cloudformation 的 AutoScaling ec2 实例
【发布时间】:2020-10-26 20:58:46
【问题描述】:

我正在尝试自动缩放此 ec2 实例,请指导我如何操作。任何可能有用的模板,以便我可以开始使用自动缩放。我只附加了我想要自动缩放的 ec2 实例模板。

---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  SourceStackName:
    Description: "Source stack name"
    Type: String
    AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
    Default: "shifa-vpc"
Resources:
  webserver:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: webserver-sg
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
          Description: For traffic from Internet
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
          Description: For traffic from Internet
      GroupDescription: Security Group for demo server
      VpcId:
        Fn::ImportValue:
          Fn::Sub: "${SourceStackName}-VpcID"
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: us-east-1a
      BlockDeviceMappings:
        - DeviceName: /dev/xvda
          Ebs:
            DeleteOnTermination: "true"
            VolumeSize: "8"
            VolumeType: gp2
      ImageId: ami-09d95fab7fff3776c # ami-0bdcc6c05dec346bf
      InstanceType: t2.micro
      #IamInstanceProfile: !Ref ListS3BucketsInstanceProfile
      #KeyName: ky-webserver
      NetworkInterfaces:
        - Description: Primary network interface
          DeviceIndex: 0
          SubnetId:
            Fn::ImportValue:
              Fn::Sub: "${SourceStackName}-PublicSubnet"
          GroupSet:
            - !Ref webserver
Outputs:
  ec2:
    Description: ec2
    Value: !Ref EC2Instance
    Export:
      Name:
        Fn::Sub: "${AWS::StackName}-server"

  sgGroupId:
    Description: ec2
    Value: !GetAtt webserver.GroupId
    Export:
      Name:
        Fn::Sub: "${AWS::StackName}-sgid"        

我是 cloudformation 的新手,正在接受培训。

【问题讨论】:

标签: amazon-web-services amazon-ec2 amazon-cloudformation autoscaling aws-auto-scaling


【解决方案1】:

Amazon 有一些 examples 用于 AutoScaling 实例。

重要的是,EC2 实例资源不属于 CloudFormation 中的自动扩展配置。

您将使用Launch TemplateLaunch Configuration 资源。启动模板较新,因此您最好使用它。这些将定义实例配置,例如卷、实例类型等。

另一个组件是Autoscaling Group,它将引用之前的任一组件并定义实例应如何扩展。

如果您尝试扩展现有实例,您需要先从它make an AMI 并引用它。

AWS 有一个带有自动缩放组 here 的示例模板。

【讨论】:

    猜你喜欢
    • 2013-02-27
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2012-05-21
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    相关资源
    最近更新 更多