“Sync EC2 with Bucket from CLI”

s3 Bucket

ec2 talks to the bucket

create a role

The first thing to do here was to create a Role, this enables connectivity between 2 services. The role will enable communication between the EC2 and the bucket. I selected a policy which granted Full S3 Access. 

build ec2 with role

Next I spun an EC2 instance, a t.2 micro AMI. Ensuring its in the role created above.  I logged on the server and ready to sync with bucket.

list bucket contents from cli

As the role grants access to one another. I have shown in the command that I am able to list the contents stored in the aws s3 location. There you can see 3 buckets. cold-customerdetails, contractorweb application and wanderema-fan-page.

verify on aws console

Looking into the buckets contents in the AWS console verifies this. The same contents are listed.  

list bucket contents

If I list the contents in the wanderema-fan-page bucket you can see the same contents show in the previous project. Assets, images and index.html.


cd /var/www/html

Now going into the publishing page directory. There is nothing stored in the directory. 

start server

Start the httpd service to enable website hosting. 

Andrew michaels

This the public DNS and IP assigned to my ec2 instance. I will use this address to enter into the url. 


Robert Jeffries

I then ran a command to sync a particular bucket on the console to the /var/www/html directory. 

contents from once device and service from another device working together to publish a webpage

Jillian Scott

The proves the project was successful and the webpage is able to publish using the IP address of the EC2 instance. So in effect the web server service is publishing contents contained in the an outsude source, the AWS bucket enabled by the syncing mechanism. 

Now make bucket from cli

make bucket

The simple command aws mb s3://blacksmoke-boxer create a new bucket into the console from the CLI. I made a txt file with one sentence of writing in it and copied it into the bucket. To confirm this same txt file is synced I shall check the bucket in the console.  


There you see the new bucket created on the top called blacksmoke-boxer. 

Robert Jeffries

Within that bucket is contained the same txt file we creating the CLI.

Close Menu