Reputation: 11
Help I can't figure out what is wrong with my ecs cloudformation stack below are the error and my code. I'm totally at a lost, I keep on getting the error "Received 0 SUCCESS signal(s) out of 1. Unable to satisfy 100% MinSuccessfulInstancesPercent requirement". Can anyone please explain what is wrong with the template?
Description: >
ECS Cluster configuration Template - CI & CD over AWS
Parameters:
InstanceType:
Type: String
Default: t2.small
ClusterSize:
Type: Number
Default: 2
Subnets:
Type: List<AWS::EC2::Subnet::Id>
SourceSecurityGroup:
Type: AWS::EC2::SecurityGroup::Id
VpcId:
Type: AWS::EC2::VPC::Id
VpcDefaultSG:
Type: String
ECSAMI:
Description: ECS-Optimized AMI ID
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id
Mappings:
AWSRegionToAMI:
eu-west-1:
AMI: ami-bff32ccc
ap-southeast-1:
AMI: ami-c9b572aa
ap-southeast-2:
AMI: ami-48d38c2b
eu-central-1:
AMI: ami-bc5b48d0
ap-northeast-2:
AMI: ami-249b554a
ap-northeast-1:
AMI: ami-383c1956
us-east-1:
AMI: ami-60b6c60a
sa-east-1:
AMI: ami-6817af04
us-west-1:
AMI: ami-d5ea86b5
us-west-2:
AMI: ami-f0091d91
Resources:
ECSRole:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: !Sub ecs-${AWS::StackName}
AssumeRolePolicyDocument: |
{
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": [ "ec2.amazonaws.com" ]},
"Action": [ "sts:AssumeRole" ]
}]
}
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref ECSRole
SecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: !Sub ${AWS::StackName}-SG-ECS-hosts
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref SourceSecurityGroup
IpProtocol: -1 #-1 value to allow all traffic in the security group
VpcId: !Ref VpcId
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Ref AWS::StackName
AutoScalingGroup:
DependsOn: Cluster
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref Subnets
LaunchConfigurationName: !Ref LaunchConfiguration
MinSize: 2
MaxSize: 6
DesiredCapacity: 2
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} - ECS Host
PropagateAtLaunch: true #specify that the new tag will be applied to instances launched after the tag is created
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 1
PauseTime: PT15M
SuspendProcesses:
- HealthCheck
- ReplaceUnhealthy
- AZRebalance
- AlarmNotification
- ScheduledActions
WaitOnResourceSignals: true
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: !Ref ECSAMI
InstanceType: !Ref InstanceType
IamInstanceProfile: !Ref InstanceProfile
KeyName: cicdoverawsKeyPair
SecurityGroups:
- !Ref SecurityGroup
- !Ref VpcDefaultSG
UserData:
"Fn::Base64": !Sub |
#!/bin/bash
yum install -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration
/opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
configSets:
InstallAndRun:
- Install
- Configure
Install:
packages:
yum:
git: []
docker: []
files:
/etc/cfn/cfn-hup.conf:
mode: 000400
owner: root
group: root
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
interval=6
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.LaunchConfiguration.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup --configsets InstallAndRun
services: #service key define which services should be enabled or disabled when the instance is launched
services: #service key define which services should be enabled or disabled when the instance is launched
sysvinit: # the key above is uspported by sysvinit
cfn-hup:
enabled: true
ensureRunning: true
files: # we want the cfn-hub to use the configuration files from below
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf
Configure:
commands:
01_add_instance_to_cluster:
command: !Sub echo ECS_CLUSTER=${Cluster} > /etc/ecs/ecs.config
CreationPolicy:
ResourceSignal:
Timeout: PT5M
Outputs:
ClusterName:
Description: ECS cluster Name
Value: !Ref Cluster
Upvotes: 1
Views: 416
Reputation: 238199
cfn-signal
in your ASG should signal ASG, not the launch configuration.
Thus, you can change for cfn-signal
:
--resource LaunchConfiguration
into
--resource AutoScalingGroup
assuming everything else with the template is fine.
Upvotes: 1