This project provides a proof-of-concept (POC) to mount an AWS S3 bucket into an EC2 instance using Terraform. It sets up the necessary components including VPC, S3 bucket, IAM policies, EC2 key pair, and the EC2 instance with Amazon Linux. The S3 bucket is then mounted into the EC2 instance.
- Terraform 1.5.4+ installed
- AWS CLI configured with appropriate access
- VPC with S3 Endpoint: Network resources and endpoint for S3 access.
- S3 Bucket: The bucket to be mounted.
- S3 Object: A text file within the S3 bucket.
- IAM Policies: Required permissions for the EC2 instance to access the S3 bucket.
- EC2 Key Pair: Key pair used for EC2 instance.
- EC2 Instance with Amazon Linux: Instance where the S3 bucket will be mounted.
Clone this repository and navigate into the project directory.
To download and initialize the necessary providers and modules, run:
terraform init
Review the changes before applying with:
terraform plan -out=plan.out
Apply the planned changes:
terraform apply plan.out
- /mount_s3 is created when the EC2 instance boots the first time using UserData
- The EC2 instance is set up to mount the S3 bucket at /mount_s3 directory.
- Terraform places a test file in the S3 bucket -
s3_file.txt
. - EC2 instance profile allows permissions to S3 bucket and allows access connect with SSM.
sudo cat /mount_s3/s3_file.txt
When you're done experimenting, you can destroy all created resources with:
terraform destroy
- The EC2 instance is set up to mount the S3 bucket at /mount_s3 directory.
- Please ensure that you have the necessary permissions and access to perform these operations in AWS.