# Connect S3 with EC2

### Create S3 bucket with the following information:

* Bucket name: `must be globally unique`
    
* AWS Region: `your choice`
    
* Object Ownership: `ACLs enabled`
    
* uncheck `Block all public access`
    
* Check `I acknowledge that the current settings might result in this bucket and the objects within becoming public.`
    
* **Bucket Versioning:** `enable (preferred) or disable as your requirement`
    
* `Create bucket`
    
* Click on `bucket name` and upload the object you want for example any `image`
    
* While uploading scroll down and open `> Permission`
    
    Predefined ACLs: `Grant public-read access`
    
    `I understand the risk of granting public-read access to the specified objects.`
    
    \[ NOTE: if you forget to give ACL public access `check object` goto `^Action` and scroll down and `click make public using ACL` \-&gt; `Make public`
    
* open bucket -&gt; Check the object and `Copy URL`
    

### Create EC2 instance with the following information:

* Name: `my-server`
    
* Key pair: `create new key pair`
    
    * Key pair name: `mykeypair`
        
    * Private key file format: `.ppk For PuTTY user` `.pem For use with OpenSSH`
        
* `Allow SSH traffic`  
    `Allow HTTP traffic from the internet` (*note you may also enable* `https` )
    
* `Launch instance`
    

### Run virtual machine

* Connect EC2 using the key you downloaded either by putty or ssh
    
* After connected as `ec2-use`
    
    ```bash
    ]$ pwd
    /home/ec2-user
    ```
    

Install Apache server

```bash
]$ sudo yum install httpd -y
```

```bash
]$ sudo systemctl status
● ip-172-31-84-163.ec2.internal
    State: running
    Units: 281 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 2023-06-01 17:42:25 UTC; 16min ago
  systemd: 252.4-1161.amzn2023.0.4
```

```bash
]$ cd /var/www/html
]$ pwd

]$ sudo nano index.html
```

* Paste the copied URL of the object as:
    

```xml
<img src="https://my-uniue-bucket-1.s3.amazonaws.com/Shared_Responsibility_Model_V2.59d1eccec334b366627e9295b304202faf7b899b.jpg"/>
```

```bash
]$ sudo systemctl start httpd
]$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: active (running) since Thu 2023-06-01 18:08:55 UTC; 17s ago
       Docs: man:httpd.service(8)
   Main PID: 26020 (httpd)
```

### Now you can access your S3 object using the public IP of EC2 instance

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685643626252/7f307b53-4a3e-466f-99d8-6abf04eb4b25.jpeg align="center")

# ....../ THANK YOU FOR YOUR TIME \\.....
