

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Identity and Access Management (IAM)
incomplete
2: IAM Users
incomplete
3: Inline Policies
incomplete
4: IAM Groups
incomplete
5: IAM Roles
incomplete
6: Deny Policies
incomplete
7: SSM Parameters
incomplete
8: SSM Parameters Are Strings
incomplete
9: Accessing SSM Parameters from EC2
incomplete
10: Use SSM from EC2
incomplete
11: Cleanup
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Okay, so we can give our users (e.g. developers) access to AWS resources... but what happens when we need our application server to be able to access a resource? For example, an EC2 instance that needs to read from an S3 bucket?
We could create a user for our server, but by using a username and password, but we'll eventually encounter this dreadful message:
Luckily, IAM has roles. A role is a temporary identity that can be used or assumed by trusted parties.
The process is simple:
A trust policy looks a lot like a "regular" policy, with a couple of tweaks:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Principal field specifies which service or entity can assume the role.sts:AssumeRole action allows the specified principal to assume the role.When you select "EC2" as the use case, AWS automatically creates this trust policy for you. The trust policy tells AWS which services can assume this role (in this case, EC2 instances). You can view it later in the role's "Trust relationships" tab.
Create an IAM role patientping-ec2-readonly-role for EC2 with the patientping-ec2-readonly policy, then attach the role to your EC2 instance.
Cost check: Creating IAM roles is free; costs arise from service usage.
You should now see the IAM role listed in the instance details.
Run and submit the CLI tests.
Here's some CLI boilerplate to get you started with IAM roles:
# Create a role with trust policy
aws iam create-role --role-name ROLE-NAME --assume-role-policy-document file://TRUST-POLICY.json
# Attach a policy to the role
aws iam attach-role-policy --role-name ROLE-NAME --policy-arn POLICY-ARN
# Create an instance profile and add the role
aws iam create-instance-profile --instance-profile-name PROFILE-NAME
aws iam add-role-to-instance-profile --instance-profile-name PROFILE-NAME --role-name ROLE-NAME
# Associate the instance profile with an EC2 instance
aws ec2 associate-iam-instance-profile --instance-id INSTANCE-ID --iam-instance-profile Name=PROFILE-NAME