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
已提問 8 個月前檢視次數 1072 次
2 個答案
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
已回答 8 個月前
  • 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
專家
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南