DEV Community

deepika n
deepika n

Posted on

EC2 + S3 + IAM

Create an EC2 Instance
Go to Ec2 in AWS Console
Click Instance
Launch Instance

Provide Instance name

Image description

Choose Amazon Linux

Image description

Select t2.micro as Instance type

Image description

Create a new key pair and download the pem file
Scroll to the bottom of the page and click launch instance

Image description

Now a page will show the available running instances
Select the instance
Go to security

Image description

Scroll down and there will be Inbound rules

Image description

Click on edit inbound rules and select Custom and that will show a dropdown and Select MyIP

Image description

Click on Save Changes

Now install Putty in your Laptop and open it

Image description

Follow these steps

Connection -> ssh -> Auth -> Credentiels

click on browse and paste the ppk file .

(if it is formated as pem convert it into ppk using puttygen.)

Select accept and the page will show "Login as" type "ec2-user"

Your Terminal gets opened in that just create a file and add some contents in it.

Command to create a file

cat < "file_name.txt"

To view the content in the file

cat "file_name.txt"

Image description

Now Go to AWS Console , IAM -> Roles -> Create Role

Image description

This role will have S3 full access

You can view your Roles as in the image below

Image description

Go to EC2 instance and select the instance

Actions -> security -> Modify IAM Role

Now select the created IAM role in the dropdown and update IAM role

Image description

Go to the terminal, we need to put the created file in the AWS S3 so enter the command

aws s3 cp "file_name.txt s3://"bucket_name"

If there is no bucket in the S3 then create it by using the command.

aws s3 mb s3://"bucket_name"

After creating it upload the created file in the bucket by using the command.

aws s3 cp "file_name.txt s3://"bucket_name"

Image description

After uploading the files go check your AWS console to verify

Image description

Completing every steps terminate all the services (EC2, S3, IAM role)

Image description

Image description

Top comments (0)