Accessing S3 from EC2 instances
Now that we have launched an EC2 instance in Chapter 1 and created S3 buckets in Chapter 2, naturally, we will ask the question: do my EC2 instances have access to my S3 buckets?
To answer this question, we need to look at it from two perspectives:
- S3 is a public endpoint, so the EC2 instance needs to have a public IP address.
However, that’s not enough – when you log into the EC2 instance, and run the command (as shown in the following figure):
aws s3 ls
You will find that there are no S3 buckets listed:
Figure 2.14 – No S3 bucket is found from EC2
- To have an EC2 instance access S3 buckets, we need to assign an IAM role to the EC2 instance. Recall that we briefly covered this in the EC2 section in Chapter 1:
An IAM role can be assigned with permissions to access other AWS resources, such as reading an Amazon Simple Storage Service (S3) bucket. By attaching the IAM...