Running ECS task in boto3

0

I have created an image in ECR, a Task Definition, and Cluster. I successfully ran a task using the console but no luck using boto3. The status of the task is stuck at PENDING and no logs were generated. Here's my code:

client = boto3.client('ecs')
overrides = {
    'containerOverrides': [
        {
            'name': 'my-container'   
        }
    ]
}
client.run_task(
	taskDefinition=JOB_DEFINITION_ARN,
   	cluster=JOB_CLUSTER_ARN,
    count=1,
    launchType='FARGATE',
    platformVersion='LATEST',
    networkConfiguration={
        'awsvpcConfiguration': {
            'subnets': SUBNETS,
            'securityGroups': [
                SEC_GROUP
            ],
            'assignPublicIp': 'DISABLED',
        }
    },
    overrides=overrides,
)

How can I properly run my task using boto3?

Vince
preguntada hace 8 meses1070 visualizaciones
2 Respuestas
0

Hi Vince,

Please ensure that the IAM role which you are using has the necessary permissions to run tasks on ECS, describe task definitions, and other relevant actions.

profile picture
respondido hace 8 meses
  • Any hint on how to check this? My task definition works when I run the task in web console.

0

Hi,

The section "cluster examples" of https://docs.aws.amazon.com/AmazonECS/latest/developerguide/security_iam_id-based-policy-examples.html will provide with examples of various IAM policies to execute various ECS under your IAM role.

You can copy those policies and adapt them to your specific use case with the actions that you need to do from boto3.

Best,

Didier

profile pictureAWS
EXPERTO
respondido hace 8 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas