I would like to start a task definition on an instance within my cluster (not in the default one). So something like:
I have tried to use these functions form boto3 (ec2, ecs)
I managed to run an instance with run_instances, it works perfectly well but I want to run an instance in my cluster. Here is my code:
def run_instances():
response = ec2.run_instances(
BlockDeviceMappings=[
{
'DeviceName': '/dev/xvda',
'Ebs': {
'DeleteOnTermination': True,
'VolumeSize': 8,
'VolumeType': 'gp2'
},
},
],
ImageId='ami-06df494fbd695b854',
InstanceType='m3.medium',
MaxCount=1,
MinCount=1,
Monitoring={
'Enabled': False
})
return response
There is a running instance on ec2 console but it doesn't appear in any of the clusters in the ecs console (I tried it with an ecs-optimized ami and with a regular one).
I also tried to follow these steps for getting my system up and running in a cluster without success: https://github.com/spulec/moto/blob/master/tests/test_ecs/test_ecs_boto3.py
Could you please help me find out what do I miss? Is there ant other setup have to make beside calling these SDK functions?
Thank you!
You will need to run an instance that uses ECS Optimized AMI
since those AMIs have ECS agent preinstalled on them otherwise you would need to install ECS agent yourself and bake a custom AMI.
By default, your ECS optimized instance launches into your default cluster, but you can specify alternative cluster name in UserData
property of run_instances
function
#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config
The list of available ECS AMIs is available here