In this article, you will learn how to share files from Amazon S3 Bucket to Amazon EC2 Instance in detailed.
► Login to the AWS Management Console and navigate to Amazon S3. Check the files that need to be transferred.
Creating IAM Role
► Navigate to IAM and click on Create role.
► Select the type and choose the use case as EC2 as the files need to be transferred from S3 to EC2.
► Attach the AmazonS3FullAccess policy to the role and click on next.
► Give the role a name and review it. Finally, click on Create.
► The role got created successfully.
Creating Key Pair and Security Group
► Navigate to the EC2 dashboard and click on Create key pair.
► Give a name for the key pair, select the file format and click on create.
► The key pair gets created and will be downloaded in the system.
► Now, go to Security groups and click on Create security group.
► Specify the essential details and the Inbound rules for the security group. Click on Create.
► The security group gets created.
Creating EC2 Instance
► Go to Instances and click on Launch Instance.
► Choose an AMI; I would recommend Amazon Linux 2 AMI as it is a free tier.
► Choose the Instance type; I would recommend t2.micro as it is a free tier.
► Configure the Instance details. Select the IAM role created before and click on Next.
► Select the Security group created before and click on Review and Launch.
► Review the Instance and click on Launch.
► Select the key pair which was created before and click on Launch.
► The EC2 Instance gets launched successfully. Select the Instance and click on Connect.
Connecting EC2 Instance
► Connect the EC2 Instance using an SSH client.
► Open the terminal and enter the following commands:
To make the Key Pair private
Command: “chmod 400 keypair.pem”
To connect the EC2 Instance
Command: ssh -i “kp.pem” email@example.com
Finally, the EC2 Instance gets connected through SSH.
► Enter as a root user by using the following command,
Command: sudo su
Update the system using,
Command: yum update -y
► Enter the following command to transfer files from S3 to EC2 Instance.
Command: aws s3 cp s3://bucketname/foldername/filename copied-filename
Now, click ls, and the copied file name gets displayed.
Tip: You can also use wget command of Linux to directly download the required file from your S3 bucket into your EC2 Instance.
Command: sudo wget file-link-in-s3-bucket
I also run a small youtube channel on some exciting topics, do look into it. 🙂