IAM Roles for EC2
Now we are going to take a practical look at how roles and policies work for an EC2 instance by having an EC2 instance access S3 and CloudWatch.
We will start with a basic example using the cli. Then we'll build upon this to have our web app interact with S3 and CloudWatch.
Setup
Let's start by creating a new S3 bucket and EC2 instance. To keep things simple, do everything in the same region.
Once the instance is created, login to the instance using ssh. We're now going to install the aws cli on the instance to interact with the S3 bucket.
You should see the error:
Which is just saying we don't have permission to list the objects in that bucket. So let's setup an IAM role to allow the EC2 instance to access the S3 bucket.