Step 1: Launch an EC2 Instance
- Navigate to the EC2 Dashboard in the AWS Management Console.
- Click on Launch Instance.
- Select the desired Amazon Machine Image (AMI).
- Choose an instance type (e.g., t2.micro).
Step 2: Create a Key Pair
- During the EC2 setup, create a new Key Pair or use an existing one.
- Download the private key file (
.pem
) and keep it secure.
Step 3: EC2 Instance Created
- Complete the EC2 setup process and launch the instance.
- Note the Public IP of your instance.
Step 4: Download PuTTY
- Download PuTTY from the official PuTTY site.
Step 5: Install PuTTY
- Install PuTTY and PuTTYgen on your local machine.
Step 6: Edit Inbound and Outbound Rules
- Go to the Security Groups associated with your EC2 instance.
- Edit the Inbound Rules to allow SSH (port 22) from your IP address.
- Optionally, update Outbound Rules as needed.
Step 7: Change Security Groups and Whitelist Your IP
- Ensure that the inbound rules whitelist only your IP address for SSH access.
Step 8: Open PuTTY and Connect to the EC2 Instance
- Open PuTTY and configure it to connect to your EC2 instance:
- Enter the Public IP of the EC2 instance.
- Load your private key (
.pem
) file in PuTTYgen and save it as a.ppk
file. - Use the
.ppk
file in PuTTY to authenticate. - Connect to the EC2 instance.
Step 9: Run Commands on the Connected Instance
Run any Linux commands to generate or process data.
Step 10: Save Output to a File
- Use the following command to save output to a file:
echo "714022205029-durgav" > details.txt
Step 11: IAM Role Setup
- Navigate to the IAM Dashboard in the AWS Management Console.
- Start creating a new role with the following permissions:AmazonS3FullAccess or a custom policy for specific bucket access.
Step 12: Role Created
1.Complete the role creation process and name the role appropriately.
Step 13: Attach the Role to the EC2 Instance
- Attach the newly created IAM role to your EC2 instance:
- Go to the EC2 Dashboard.
- Select your instance and choose Actions > Security > Modify IAM Role.
- Attach the role.
Step 14: Verify IAM Role Connection
1.Run the following command to verify the IAM role is working:aws s3 ls
Step 15: Upload the File to an S3 Bucket
- Use the following command to upload the file to S3:
aws s3 cp details.txt s3://714022205029/
Step 16: Delete the IAM Role
1.After completing the tasks, delete the IAM role if it's no longer needed.
Step 17: Terminate the EC2 Instance
1.Go to the EC2 Dashboard and terminate the instance to stop incurring charges.
This step-by-step guide ensures you can securely run Linux commands on an EC2 instance, upload the output to S3, and clean up resources afterward.
Top comments (0)