I'm using below code to launch fargate instances, here I've a doubt what if fargate spot instance not available, does it launch an normal instance by default or raise an exception ??
I went through boto3 docs, I'm not not able to find it.
import boto3
ecs_client = boto3.client('ecs')
# Set the parameters for the task
cluster_name = 'my-cluster'
task_definition = 'my-def'
capacity_provider = 'FARGATE_SPOT'
# Launch the task
response = ecs_client.run_task(
cluster=cluster_name,
taskDefinition=task_definition,
capacityProviderStrategy=[
{
"capacityProvider": capacity_provider
}
],
networkConfiguration={
'awsvpcConfiguration': {
'subnets': [
'subnet-001',
],
'securityGroups': [
'sg-001',
],
'assignPublicIp': 'ENABLED'
}
},
)
CodePudding user response:
No, it will not switch to on-demand instance on FARGATE
and you will not get any raise exception. You can only see it on service metrics spot capacity not available.
Solution is to combine FARGATE
and FARGATE_SPOT
together with weight.
capacityProviderStrategy=[
{
'capacityProvider': 'FARGATE_SPOT',
'weight': 4
},
{
'capacityProvider': 'FARGATE',
'weight': 1
},
]
20%
on FARGATE
and 80%
on FARGATE_SPOT