更新堆栈

时间:2018-10-11 14:32:41

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

在尝试使用以下代码更新堆栈时,我得到ROLLBACK_COMPLETE。在事件下,我不会收到错误消息,因为“属性SecurityGroupIds的值必须为字符串列表类型”。请帮助我找到解决方案。

第一个堆栈的Mycode:

Resources:
  myvpc:
    Type: AWS::EC2::VPC
    Properties:
        CidrBlock: 10.0.0.0/16
        EnableDnsSupport: true
        EnableDnsHostnames: true
        InstanceTenancy: default
        Tags:
            - Key: Name
              Value: myvpc

 myinternetgateway:
    Type: AWS::EC2::InternetGateway
    Properties:
        Tags: 
            - Key: Name
              Value: mygtwy

 mygatewayattach:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
        InternetGatewayId: !Ref myinternetgateway
        VpcId: !Ref myvpc

 mysubnet1:
    Type: AWS::EC2::Subnet
    Properties:
        AvailabilityZone: us-east-1a
        VpcId: !Ref myvpc
        CidrBlock: 10.0.1.0/24
        MapPublicIpOnLaunch: true

 Routetable:
    Type: AWS::EC2::RouteTable
    Properties:
        VpcId: !Ref myvpc

 Route:
    Type: AWS::EC2::Route
    DependsOn: myinternetgateway
    Properties:
        DestinationCidrBlock: 0.0.0.0/0
        GatewayId: !Ref myinternetgateway
        RouteTableId: !Ref Routetable

 SubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
        RouteTableId: !Ref Routetable
        SubnetId: !Ref mysubnet1

关于更新,我添加了以下内容。在这段时间里,我遇到了前面提到的错误

 Myec2:
    Type: 'AWS::EC2::Instance'
    Properties:
        SecurityGroupIds:
            - !Ref Mysecgroup
        KeyName: !Ref KeyName
        ImageId: ami-0922553b7b0369273
        InstanceType: t2.micro
        SubnetId: !Ref mysubnet1

 Mysecgroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
        GroupDescription: Enable SSH access via port 22
        VpcId: !Ref myvpc
        SecurityGroupIngress:
            - IpProtocol: tcp
              FromPort: '22'
              ToPort: '22'
              CidrIp: 0.0.0.0/0  

2 个答案:

答案 0 :(得分:2)

  

当您将AWS :: EC2 :: SecurityGroup类型指定为   引用函数,AWS CloudFormation返回安全组名称或   安全组ID(对于不在其中的EC2-VPC安全组   默认VPC)。

您的模板在引用安全组名称的位置引用了安全组名称。

Myec2:
    Type: 'AWS::EC2::Instance'
    Properties:
        SecurityGroupIds:
            - !GetAtt "Mysecgroup.GroupId"
        KeyName: !Ref KeyName
        ImageId: ami-0922553b7b0369273
        InstanceType: t2.micro
        SubnetId: !Ref mysubnet1

 Mysecgroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
        GroupDescription: Enable SSH access via port 22
        VpcId: !Ref myvpc
        SecurityGroupIngress:
            - IpProtocol: tcp
              FromPort: '22'
              ToPort: '22'
              CidrIp: 0.0.0.0/0 

答案 1 :(得分:0)

按名称引用安全组(而不是SecurityGroupIds)对我有用:

EC2SG1IKTA:
    Type: 'AWS::EC2::SecurityGroup'
EC2I1K240:
    Type: 'AWS::EC2::Instance'
    Properties:
      SecurityGroups:
        - !Ref EC2SG1IKTA
相关问题