Amazon web services 我的Cloudformation YAML for autoscaling组在默认VPC中不断创建EC2实例,即使我指定了自定义VPC
我的Cloudformation YAML for autoscaling group一直在默认VPC中创建EC2实例,即使我指定了自定义VPC。以下是代码片段:Amazon web services 我的Cloudformation YAML for autoscaling组在默认VPC中不断创建EC2实例,即使我指定了自定义VPC,amazon-web-services,amazon-cloudformation,aws-auto-scaling,Amazon Web Services,Amazon Cloudformation,Aws Auto Scaling,我的Cloudformation YAML for autoscaling group一直在默认VPC中创建EC2实例,即使我指定了自定义VPC。以下是代码片段: TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: Port: 80 Protocol: HTTP VpcId: !Ref VpcId 参数部分: VpcId: Descri
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Port: 80
Protocol: HTTP
VpcId: !Ref VpcId
参数部分:
VpcId:
Description: Enter the VpcId
Type: AWS::EC2::VPC::Id
Default: vpc-0ed238eeecc11b493
我一直看到EC2实例的终止,因为启动配置出于某种原因在默认VPC中创建实例,即使我在参数部分指定使用自定义配置。我不知道为什么不使用自定义VPC。当我检查安全组时,AWS控制台中的launch config会显示自定义VPC,但当我检查自动缩放组启动的EC2实例时,我会看到默认的VPC。
我的默认VPC是VPC-6a79470d
,我的自定义VPC是VPC-0ed238eeecc11b493
我在控制台的自动缩放组部分看到的错误是:
Description:DescriptionLaunching a new EC2 instance: i-041b680f6470379e3.
Status Reason: Failed to update target group arn:aws:elasticloadbalancing:us-west-1:targetgroup/ALBTe-Targe-7DMLWW46T1E6/f74a31d17bf3c4dc:
The following targets are not in the target group VPC 'vpc-0ed238eeecc11b493': 'i-041b680f6470379e3' Updating load balancer configuration failed.
希望有人能帮我指出我做错了什么。我在AWS文档中看到,默认情况下,ASG在默认VPC中启动,但如果可以通过控制台执行,则必须有一种在CloudFormation中执行此操作的方法
====================================================更新后==========================
下面是添加VPCZoneIdentifier后的外观,不确定我做错了什么,现在安全组出现了问题
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones: !GetAZs
VPCZoneIdentifier: !Ref SubnetIds
LaunchConfigurationName: !Ref LaunchConfiguration
MinSize: 1
MaxSize: 3
TargetGroupARNs:
- !Ref TargetGroup
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
KeyName: !Ref KeyName
InstanceType: t2.micro
SecurityGroups:
- !Ref EC2SecurityGroup
ImageId:
Fn::FindInMap:
- RegionMap
- !Ref AWS::Region
- AMI
LaunchConfiguration --region ${AWS::Region}
ALBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ALB Security Group
VpcId: VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
EC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: EC2 Instance
您提供的代码段是针对负载平衡器的目标组的 发生此错误的原因是,连接到自动缩放组的子网与目标组不在同一VPC内
为该参数类型使用
列表的参数类型。在ASG中,您通常会定义:
- 虚拟私有云(VPC)的子网ID列表。如果使用AvailabilityZones指定VPCZoneIdentifier,则为此属性指定的子网必须位于这些可用性区域中
示例如下:
Parameters:
SubnetIds:
Type: List<AWS::EC2::Subnet::Id>
Description: Subnet IDs for ASG
Resources:
MyASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
# ... other properties
VPCZoneIdentifier: !Ref SubnetIds
参数:
子网:
类型:列表
描述:ASG的子网ID
资源:
MyASG:
类型:AWS::AutoScaling::AutoScalingGroup
特性:
# ... 其他属性
VPCZoneIdentifier:!参考子网
autoscaling group的CloudFormation在哪里?能否显示您的启动配置和autoscaling模板?感谢您的帮助……问题已转移到该ALB的安全组。我现在收到这个错误:启动配置中的一个或多个安全组未链接到自动扩展组中配置的vpc(服务:AmazonaAutoScaling;状态代码:400;错误代码:ValidationError;请求ID:83c8106b-149a-4ff3-b59b-4f151313206e)@SantoshR安全组还必须与您的vpc关联,使用参数。我刚刚用更改后的YAML更新了我的原始帖子。VPCid位于安全组中definition@SantoshR这是不正确的yamlVpcId:VpcId:!参考VpcId
。另外,EC2SecurityGroup
不在您的专有网络中。绝对!谢谢下面是它现在的样子: