Session 3's second EC2 lesson in twenty-eight slides: a role for EC2, with the EC2 service as the trusted principal, the instance profile, iam:PassRole, EC2's AssumeRole step by step, the credentials in the instance metadata service and IMDSv2, the credential chain and its trap, the CLI and an SDK on the instance, changing a role while the instance runs and stolen instance credentials; user data and cloud-init; Session Manager beside SSH and EC2 Instance Connect; placement groups. Every section ends with five exam questions.
The slides
The tool is twenty-eight slides: an introduction, then four sections, listed on its left. Every section ends with five
exam questions, each with its answer and the tempting wrong answer.
- 0. Introduction
- Roles, user data, Session Manager and placement groups: the four things this lesson adds to an instance.
- 1. Roles for EC2
- Credentials for a program on an instance: a stored key, and where its copies go; a role instead.
- The EC2 service as the trusted principal: the trust policy and the lab's permissions policy.
- Creating a role for EC2 in the console: the wizard's three steps.
- The instance profile: the container that holds the role, from the console and the CLI.
- iam:PassRole: who may give a role to an instance.
- AssumeRole by EC2, step by step: EC2, STS, the instance and S3.
- The lifetime of the instance's credentials: a new set before the old one expires.
- IMDS: the instance metadata service, and reading the credentials from IMDS by hand.
- IMDSv2: a session token against forged requests: SSRF, the hop limit, the AL2023 AMI's setting.
- The credential chain: where the CLI and the SDKs look, and the key that wins over the role.
- The AWS CLI and an SDK on the instance: allowed and refused.
- Changing a running instance's role.
- Stolen instance credentials, and the defences.
- 2. User data
- User data: a script for the first boot: cloud-init, and the project's script.
- cloud-init's log, and the readers of the user data.
- The rules user data follows: 16 KB, base64, once, as root.
- 3. Session Manager
- Session Manager: the agent's outbound connection.
- What Session Manager needs: the agent, the role, the way out, our permission.
- A Session Manager session.
- SSH, EC2 Instance Connect and Session Manager, side by side.
- 4. Placement groups
- Placement groups: cluster, partition and spread.
- Choosing a placement group: the workload decides.
The buttons on the left and right edges move between slides. So do the arrow keys and a swipe.
It follows
Elastic Compute Cloud (EC2) and builds on
IAM Roles. The lab
Amazon EC2 Lab: a Role and Session Manager
practices it.
The Amazon Linux 2023 AMI's ImdsSupport (v2.0) and the managed policy AmazonSSMManagedInstanceCore were read from
an account with the CLI on 2026-11-16. The terminals' outputs are written from AWS's documentation; the instance ID,
keys and addresses are placeholders: AWS's i-1234567890abcdef0 and ASIAIOSFODNN7EXAMPLE, and the documentation
ranges.
Sources