Hosting a Dynamic Site on AWS.
Introduction.
This article is a walkthrough on how to host a dynamic website on AWS using S3 and EC2.
AWS Services required include: S3 (for storage), EC2 (to launch a virtual machine), and IAM (to assign roles for S3 to interact with EC2)
Steps
1. Login to your AWS account.
2. Navigate to S3 to create a bucket.
3. Upload source code from local machine as an object in the just created S3 bucket.
4. Navigate to IAM dashboard to assign a role to make EC2 access S3 / perform some actions.
5. Under Access Management go to Roles, click on create roles.
6. Choose the AWS service as the entity type, and choose EC2 as use case.
7. Search for S3 to grant permission, and select AmazonS3FullAccess
8. Give the role a name, description and tag (this is optional), then click on create role button.
9. Notice that a new role has been created.
10. Navigate to EC2, then instances, to launch an instance.
11. Give the instance a name.
12. Click Create New Key Pair
to create key pair, which will be used to connect to my instance.
13. Provide the key pair name and ensure .pem
is the private key file format; once the key pair is created, ensure to save it as it will be needed to connect to the instance.
14. Create a firewall/security to control traffic to instances.
15. Add the role created using the create new IAM profile
option on the IAM instance profile; Click on launch instance to launch the instance with the configurations given.
16. An instance has been launched.
17. By default, an instance's state is pending but changes to running when it is ready to be used; View details of the selected instance
18. To connect remotely (via ssh in this case), an external tool called MobaXterm will be used, Open a session and choose SSH as the session type.
19. Specify the remote host, username, and path to the private key, then click OK to get to the CLI.
20. Run the commands below on the CLI, the function of each command is included at the side of each command.
21. Copy public IPV4 DNS from instance details and paste it on a browser to view the site; Notice that Apache test page is visible, this is because my HTML file is not named index.html.
22. To make my site visible, I renamed my HTML file to index.html and re-enabled Apache.
23. I copied the public IPV4 DNS, and my site is visible, notice the URL.
24. I terminated my EC2 instance to avoid being charged.
Thank you for reading and I hope you learned something new.