setting-up-ec2-instance-profiles

Configures IAM roles and instance profiles to grant EC2 instances temporary AWS credentials.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/sakicodes/BuildFestHackathon26 --skill setting-up-ec2-instance-profiles-sakicodes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setting-up-ec2-instance-profiles
Source: https://github.com/sakicodes/BuildFestHackathon26/tree/main/.agents/skills/setting-up-ec2-instance-profiles
Command: npx skills add https://github.com/sakicodes/BuildFestHackathon26 --skill setting-up-ec2-instance-profiles-sakicodes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Applications on EC2 often rely on hardcoded AWS credentials, which is insecure and hard to rotate. This Skill guides you through granting an EC2 instance secure, temporary access to AWS services using IAM roles and instance profiles instead of embedded access keys. ## Core Features & Use Cases - Least-Privilege Permission Planning: Analyzes the services you need (S3, DynamoDB, SQS, CloudWatch, and more) and recommends scoped IAM policies instead of broad FullAccess policies. - Full Lifecycle Automation: Creates or reuses IAM roles, builds trust policies, creates instance profiles, attaches them to instances, and handles replacement of existing profiles. - Verification and Reporting: Validates the configuration with IMDSv2-based credential tests, provides SDK code examples (Python, Node.js, Java), and generates a summary report with security recommendations and cleanup steps. - Use Case: You have a web server on EC2 that needs to read from S3 and write CloudWatch logs. Provide the instance ID, region, and services, and the Skill walks you through creating a scoped role, attaching it, and verifying credentials work. ## Quick Start Ask the assistant to set up an instance profile for EC2 instance i-0123456789abcdef0 in us-east-1 with access to s3 and dynamodb.

Frequently Asked Questions about setting-up-ec2-instance-profiles

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I give an EC2 instance access to S3 without access keys?

Attach an IAM instance profile containing a role with S3 permissions to the instance. The instance then retrieves temporary credentials from the metadata service automatically, and AWS SDKs use them through the default credential chain without any hardcoded keys.

How to attach an IAM role to a running EC2 instance?

Create an instance profile, add the IAM role to it, then run aws ec2 associate-iam-instance-profile with the instance ID and profile name. If a profile is already attached, disassociate it first using its association ID before attaching the new one.

What IAM permissions does an EC2 instance need for DynamoDB?

Follow least privilege: grant specific actions like dynamodb:GetItem, PutItem, Query, and Scan scoped to specific table ARNs rather than AmazonDynamoDBFullAccess. Read-only use cases can acceptably use the AmazonDynamoDBReadOnlyAccess managed policy.

Why are instance profile credentials not available after attaching?

Instance profile propagation typically takes 30 to 60 seconds after attachment. Applications may also cache old credentials and need a restart. Verify availability by querying the metadata service with an IMDSv2 session token.

Can I reuse an existing IAM role for an EC2 instance profile?

Yes, as long as the role's trust policy allows the ec2.amazonaws.com service principal to assume it. The procedure verifies the trust policy, lists existing attached and inline policies, and lets you add permissions or use the role as-is.

How do I test EC2 instance profile credentials from inside the instance?

Use IMDSv2: first request a session token with a PUT to the metadata token endpoint, then query the iam/security-credentials path with that token. Running aws sts get-caller-identity confirms the AWS CLI picks up the role credentials.