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
asked 7 months ago1012 views
2 Answers
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
answered 7 months ago
  • 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
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions