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 个月前1073 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则