- Newest
- Most votes
- Most comments
Hello, From your logs :
Failed to assume role: User: arn:aws:sts::339712882588:assumed-role/EcsService-Alpha-EcsTaskInstanceRoleE38DB492-rq6N7a8Mxax9/0a7847a0c3c14015be3ff1deef081be1 is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::339712882588:role/EcsService-Alpha-EcsTaskInstanceRoleE38DB492-rq6N7a8Mxax9
It look likes your task, already assuming the role, "EcsService-Alpha-EcsTaskInstanceRoleE38DB492-rq6N7a8Mxax9" is trying to assume it again.
If you really need the role to assume itself please :
#1. Ensure you have an IAM Policy allowing Assuming the role itself. You can add the following inline policy to the role :
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"sts:AssumeRole"
],
"Resource":[
"arn:aws:iam::339712882588:role/EcsService-Alpha-EcsTaskInstanceRoleE38DB492-rq6N7a8Mxax9"
]
}
]
}
#2. In the trust policy, use least-privilege on role instead of allowing to assume from the whole account "arn:aws:iam::339712882588:root"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::339712882588:role/EcsService-Alpha-EcsTaskInstanceRoleE38DB492-rq6N7a8Mxax9"
},
"Action": "sts:AssumeRole"
}
]
}
#3. Additionally you can find here the documentation about Task Roles : https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
PS : Instead of self-assuming roles, you may consider having distinct roles with least-privilege strategy for your ECS task configurations
Using DefaultAWSCredsProvider Chain to use the creds for the Task Role.
@Bean(name = "awsCredentialsProvider") public AWSCredentialsProvider getAwsCredentialsProvider() { return DefaultAWSCredentialsProviderChain.getInstance(); }
Relevant content
- asked 2 years ago
- asked a year ago
- asked 5 years ago
- asked 2 years ago

Hi Jerome, Thanks for replying. I think you are correct, the above mentioned task role is being assumed to run the tasks as well as to query one of the ES dependencies. Ref: https://tiny.amazon.com/3v70slrh/codeamazpackRewablob2338src
When I added the inline policy to assume the task role as mentioned by you, The service deployment got succeeded. However the ES query is failing with
Suspecting this could be because we are trying to assume the task role again for querying ES.
So, I wanted to understand, should we create a different IAM role for accessing OpenSearch. Does this need not be the task role only ??