A hands-on EC2 lab in sixteen slides, in the console and the CLI: make the project bucket again; create the role project-web-role for EC2, with a policy that reads the bucket and the one Session Manager needs; launch the web server with the role, user data and no key pair or SSH rule; connect with Session Manager and check that no access key is stored on the instance; read the role's credentials from IMDS, use the CLI on the instance, and watch an environment variable take the role's place; change the role while the instance runs; find its requests in CloudTrail; clean up.
The slides
The tool is a hands-on lab in sixteen slides, one step each, with the steps to follow beside a terminal and a picture
of the instance, its role, the bucket and the requests tried:
- Introduction: what the lab makes.
- 1. The project bucket
- Make the project bucket again: with
index.html and notes.txt.
- 2. The role
- Create the role for EC2:
project-web-role, with AmazonSSMManagedInstanceCore. - Give the role read access to the bucket: the inline policy
read-project-bucket.
- 3. Launch with user data
- Write the user data: nginx, and the page from the bucket.
- Launch the web server with the role: no key pair, port 80 only.
- Check the instance from the CLI: the profile, IMDSv2, the page.
- 4. Session Manager
- Connect with Session Manager: a shell as
ssm-user. - Check that no access key is stored on the instance: and that port 22 is closed.
- 5. The role's credentials
- Read the role's credentials from IMDS by hand: the token, then the credentials.
- Use the CLI on the instance: what the role allows and refuses.
- Watch an environment variable take the role's place.
- 6. Change the role while it runs
- Remove the S3 policy while the instance runs, and put the S3 policy back from the CLI.
- 7. CloudTrail
- Find the instance's requests in CloudTrail: and EC2's
AssumeRole.
- 8. Clean up: the instance, the security group, the role and the bucket.
The buttons on the left and right edges move between slides. So do the arrow keys and a swipe.
The lab starts where
Getting Started with AWS ends: the CLI works as jane.
The slides
EC2: Roles, User Data and Session Manager explain what it uses.
The placeholders
The account (111122223333), the instance and security group IDs and the keys are AWS's documentation placeholders
(i-1234567890abcdef0, ASIAIOSFODNN7EXAMPLE), and 198.51.100.24 is from the documentation ranges. The bucket's
name, firstname-lastname-project, stands for one with your own name.
Sources