HeadlinesBriefing favicon HeadlinesBriefing.com

AWS DevOps Setup: S3 and EC2 Integration

DEV Community •
×

A developer successfully set up an AWS environment, focusing on S3 bucket creation and EC2 instance management. The process began with creating a bucket named believe-in-bucket on the AWS Free Tier, configuring it with default 'Block Public Access' settings and 'Bucket owner enforced' object ownership. This setup ensures that only the bucket owner can manage objects, enhancing security. Additionally, an EC2 instance running Amazon Linux 2 was launched and connected via SSH from WSL2 and VSCode Remote-SSH. The developer verified that the IAM role attached to the EC2 instance had AmazonS3FullAccess, allowing seamless communication with the S3 bucket.

The integration involved connecting the EC2 instance to the S3 bucket, where the developer used AWS CLI commands to list the bucket contents, confirming that the IAM permissions were correctly configured. Initial troubleshooting was necessary, as the developer had to create an IAM role with AmazonS3FullAccess and attach it to the EC2 instance. The connection was further verified using aws sts get-caller-identity to ensure that the EC2 instance was using the correct role.

For SSH and SCP connectivity, the developer configured the ~/.ssh/config file on both WSL2 and Windows. A successful SSH connection to the EC2 instance was established, but issues arose with SCP due to hostname resolution. The problem was resolved by ensuring that the host alias in the SSH config matched the SSH command, using the actual EC2 public DNS. VSCode Remote-SSH was also configured using the same SSH settings, though adjustments were needed for public key permissions and paths.

The developer then uploaded a DevOps folder to the EC2 instance, initially encountering issues with the folder structure and hidden files. The upload to S3 was attempted using the aws s3 cp command, but errors related to AccessControlListNotSupported and bucket policies were encountered. These issues were resolved by removing the --acl public-read flag and explicitly excluding the .git folder. The final folder structure in S3 included index.html, css/style.css, and js/app.js, with the .git folder successfully excluded. Static website hosting was enabled, requiring adjustments to bucket policies for public read access. The website was successfully served, and a minimal index.html file was created to display content.