r/aws•
83bytes

ECS Task IAM Role for cross-account resource sharing.

technical question

I have a ECS task that needs to access resources in another aws account.

My ECS tasks are running in Account A and the resources that I need to access are in account B.

For this I have created a role in account B with necessary permission to the required resources and I have added a trust relationship with account A as well.

Now in account A where ECS is running I have added sts:AssumeRole to the Remote IAM role in account B.

This however is not working. My ECS task is still not being able to access resourcecs in account B.

​

How do i set up cross-account IAM roles/policies that work with ECS Task.

Posted Mar 31, 2020, 9:56 AM UTC

35
jamsan920•

You mentioned you added sts:AssumeRole to the IAM role in account B. Did you state that right?

You should be adding AssumeRole to the IAM role in Account A that’s assigned to your ECS task.

2
83bytesOP•

Yes. that is correct.

Acc A runs the ecs service. So the IAM role in account A needs to assume a role that allows it to access some data from account B.

1
JohnPreston72•

You might be better off with getting your Task Role ID (not ARN) and in the resource you want to access add a statement in resource policy to allow that principal access to it directly therefore your task doesnt need to assume a role in the other account. Hoep that makes sense? :)

2
ictatha•

Are you actually assuming that role within your task?

You mentioned assigning the permissions to assume the role, and that your code can't access those resources. Maybe it's just the wording but it sounds like you might be skipping the step of actually assuming the role within your task's code. See Switching to an IAM Role (AWS API) (includes python example)

2
83bytesOP•

This is what i needed.

I will try this and get back.

Thank You

2