How to securely access S3 From A VPC

Today’s agenda is to launch a VPC with a public subnet and EC2 instance, and directly access/manage an AWS S3 bucket through the EC2 instance.

First we do the normal setup of a VPC. Which you can find at the following links below to get you started:

Then we create an S3 bucket and upload two files into the bucket.

Then we want to create access keys in order for our EC2 instance inside our VPC can have access to our S3 bucket.

In order to create access keys, we need to create an IAM user with though privileges. You can look over the follow tutorial on the below link to get you started.

Once you have created the IAM user and access keys we can go to the EC2 Connect Instance and connect to our EC2 instance with the IAM user. We will then type the command “aws s3 ls” to view the files in our s3 bucket.

Then to test if we really interact with our s3 bucket from within our EC2 instance, we make a file with the command “sudo touch /tmp/test.txt”, and then copy/move it to our s3 bucket with the command “aws s3 cp /tmp/test.txt s3://nextwork-vpc-project-mitchell”.

Congratulations you did it 😎🙌🎉..

Today you’ve learnt how to:

  • 🔑 Set up access keys for an EC2 instance
  • 👨🏽‍💻 Interact with S3 through the AWS CLI

Finally you can check out the step by step below:

mmoorewebdev.com
mmoorewebdev.com