Instance Profiles for EC2 Workloads
Give compute its own identity instead of embedded credentials.
Instance Profiles for EC2 Workloads is a free AWS Security Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Giving Compute an Identity
Applications on EC2 often need to call AWS APIs, but embedding access keys is dangerous. The solution is to give the instance its own identity through an instance profile, which delivers temporary role credentials automatically. This is one of the most-tested patterns for eliminating long-term secrets from workloads.
What an Instance Profile Is
An instance profile is a container for an IAM role that you attach to an EC2 instance. Although you assign a role conceptually, EC2 actually attaches the instance profile that wraps that role. When you create a role for EC2 in the console, an instance profile of the same name is created automatically; with the CLI or API you may need to create it explicitly.
How Credentials Arrive
Once an instance profile is attached, the instance can retrieve temporary credentials from the Instance Metadata Service (IMDS), a special link-local endpoint at 169.254.169.254. The AWS SDK and CLI fetch and refresh these credentials transparently, so application code never handles keys at all.
Metadata Endpoint
The credentials live under a metadata path tied to the role name. SDKs query it automatically, but understanding the path helps when troubleshooting why an instance has unexpected permissions. The command below shows where credentials are exposed on the instance.
http://169.254.169.254/latest/meta-data/iam/security-credentials/Auto-Rotation
A major benefit is that IMDS credentials are automatically rotated well before they expire. There is nothing to store, no key to leak permanently, and no rotation process to build. This is why AWS recommends instance profiles over any scheme that places static keys on a server.
IMDSv2 Matters
The original metadata service (IMDSv1) could be abused through SSRF (Server-Side Request Forgery) attacks to steal role credentials. IMDSv2 requires a session token obtained via a PUT request first, which blocks most SSRF exploits. The exam expects you to enforce IMDSv2 and ideally set the hop limit to 1 to prevent containers from reaching it.
Least Privilege for Roles
The instance-profile role should follow least privilege: grant only the specific actions and resources the workload needs. An over-broad EC2 role is dangerous because any compromise of the instance, including through SSRF, exposes those permissions. Scope policies tightly and use conditions to limit blast radius.
Replacing Embedded Keys
If you find static access keys hard-coded in an application or a credentials file on an instance, the remediation is to attach an instance profile and delete the keys. The exam often frames this as fixing a finding: the right answer removes the long-term secret and relies on the role-based credentials from IMDS.
One Role per Instance
An EC2 instance can have only one instance profile attached at a time, and thus one role. If a workload needs different permission sets, design separate roles and either separate instances or have the application assume additional roles via STS as needed, rather than over-broadening the single attached role.
Auditing Instance Access
Because the role credentials appear in CloudTrail as actions by an assumed-role session, you can audit exactly what an instance did. If an instance is compromised, snapshotting and checking CloudTrail for that role's session reveals what the attacker accessed. Tight role scope plus CloudTrail visibility is the secure, exam-favored combination.
Putting It Together
To secure EC2 access: attach an instance profile wrapping a least-privilege role, enforce IMDSv2, set the metadata hop limit to 1, and remove any static keys. The instance fetches and auto-rotates temporary credentials from IMDS, giving compute a secure identity without any secret you have to manage.
Quick Check
Check your instance-profile knowledge.
Recap
An instance profile wraps an IAM role and attaches it to EC2, delivering auto-rotated temporary credentials through the Instance Metadata Service. This removes static keys entirely. Enforce IMDSv2 and a hop limit of 1 to block SSRF credential theft, scope the role with least privilege, and audit its sessions in CloudTrail.
Frequently asked questions
Is the “Instance Profiles for EC2 Workloads” lesson free?
Yes — the full text of “Instance Profiles for EC2 Workloads” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “Instance Profiles for EC2 Workloads”?
Give compute its own identity instead of embedded credentials. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Instance Profiles for EC2 Workloads” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Comparing IAM Users and Groups
- What an IAM Role Really Is
- Trust Policies and Who Can Assume
- Instance Profiles for EC2 Workloads