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
posta 8 mesi fa1072 visualizzazioni
2 Risposte
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
con risposta 8 mesi fa
  • 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
ESPERTO
con risposta 8 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande