I would like to start a task definition on an instance within my cluster (not in the default one). So something like:
- create a cluster
- create a task definition with a docker image (I have a docker image already pushed to ecs)
- run the task definition in the cluster
- I would like to add a keypair to the ec2 instance for ssh access
I have tried to use these functions form boto3 (ec2, ecs)
- create_cluster
- run_task
- register_container_instance
- register_task_definition
- run_instances
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!