We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

ECS Permissions

We've dealt with IAM roles with EC2, but they also apply to ECS. We have two problems to solve:

  1. We need to give ECS access to specific containers to pull them in and start them up.
  2. After the container boots up, it needs to have its own set of permissions. In our case, we'll give it permissions to read SSM parameters.

Two different permission sets, and AWS handles them with:

  1. A Task Execution Role: Essentially, what permissions does ECS need to start up the task definition?
  2. A Task Role: After the task starts up, what permissions does my application running inside that container require?

I've met a lot of engineers confused about this concept, and it's partly because AWS tries to be helpful and "create" roles automatically... sometimes.

So an engineer might have tasks running happily for quite a while before they need to think about what roles/permissions they need to give to their tasks.

AWS will happily suggest creating the roles for you in the console, but we'll do it by hand so you can see exactly what's going on.

Remember, every IAM Role has a set of Permissions (what can be done) and a Trust Policy (who can use it).

Assignment

Create the IAM roles and policies needed for ECS tasks.

Cost check: IAM roles and policies are free. You only pay for the resources that use these roles.

  1. {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ecr:GetAuthorizationToken",
            "ecr:BatchCheckLayerAvailability",
            "ecr:GetDownloadUrlForLayer",
            "ecr:BatchGetImage"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
          "Resource": "arn:aws:logs:*:*:log-group:/ecs/patientping-ecs:*"
        }
      ]
    }
    
  2. {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "ReadSsmParameters",
          "Effect": "Allow",
          "Action": ["ssm:GetParameter", "ssm:GetParameters"],
          "Resource": ["arn:aws:ssm:us-east-1:*:parameter/CMO_NAME"]
        }
      ]
    }
    

Run and submit the tests to verify your IAM roles are configured correctly.