How to Copy Files from S3 to EC2 Using AWS CLI: The Exact Command & IAM Setup
A common operational task — pulling a config file, a deployment artifact, or a secrets template from S3 onto a running EC2 instance — trips up engineers not because the command is complex, but because a missing IAM permission silently blocks the transfer. This guide gives you the exact aws s3 cp command, the minimal IAM policy required, and the mental model to debug it when it fails. TL;DR Step What You Do Key Detail 1 Create an IAM Role with S3 read permission Attach to EC2 instance profile 2 Attach the role to your EC2 instance No access keys needed on the instance 3 SSH into EC2, run aws s3 cp AWS CLI uses instance metadata credentials automatically Architecture: How the Credential Flow Works Before running any command, understand how the EC2 instance authenticates to S3. It does not use hardcoded access keys. Instead, it uses an IAM Instance Profile — a container that holds an IAM Role — which th...