We have a situation where we would like to run a Django server in the usual Elastic Beanstalk manner while hooking up a custom Docker container to be used by the Django website. So far, I basically have the following .ebextensions
configuration file:
packages:
yum:
ecs-init: []
files:
/etc/ecs/ecs.config:
mode: "000644"
owner/group: root
content: ECS_CLUSTER=${Ref: MyCluster}
commands:
01_start_docker: sudo service docker start
02_start_ecs: sudo start ecs
Resources:
MyCluster:
Type: AWS::ECS::Cluster
MyService:
Type: AWS::ECS::Service
Properties:
Cluster: ${Ref: MyCluster}
DesiredCount: 1
TaskDefinition: ${Ref: MyTask}
MyTask:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- ...
The problem is that the ECS service is trying to start up before the Elastic Beanstalk-provided EC2 instance is registered with the cluster. As a result, deploying to Elastic Beanstalk hangs. If I manually SSH'ed into the EC2 instance and manually installed ecs-init
, created ecs.config
, and ran the commands, the service continues being created and the EB environment is created successfully.
Is there a way to tell the service to wait until the EC2 instance created by EB's autoscaling group is registered with the cluster?
More context:
Try something like the below. As EB is just CloudFormation stacks look at the stacks beginning with awseb- to find yours. Then look at the CF Resources while your EB app deploys to see the names used by the predefined EB resources that you aren't specifying in the .ebextensions. I see AWSEBInstanceLaunchWaitCondition in mine, which appears to relate to the initial instances launch.
Resources:
MyService:
Type: AWS::ECS::Service
Properties:
Cluster: ${Ref: MyCluster}
DesiredCount: 1
TaskDefinition: ${Ref: MyTask}
DependsOn: AWSEBInstanceLaunchWaitCondition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With