DEV Community

Cover image for EC2 Instance with an Admin Role
Ivy Jeptoo
Ivy Jeptoo

Posted on

EC2 Instance with an Admin Role

Howdy!!!
Some time back we learnt how to create and EC2 Instance and we even connected to it, don't remember? Check it out here.

  • Today we are going to create an Instance based on Amazon Linux AMI that will be connected via SSH. Using Security Groups, you will ensure that access to the instance is limited to your IP address only.
  • The CLI will be pre-installed on the instance by default. This instance only needs permissions assigned. Once the instance is up and running, create an IAM role with admin access for your account. Add the role to your EC2 after that.

Table of Content

Objectives

By the end of this article, you'll be able to:

  • Launch a secure EC2 instance.
  • Create IAM role with admin previleges
  • Attach the IAM role to the your Instance.
  • Connect to your EC2 instance via SSH
  • Use CLI tool in the Instance.

Create a default Virtual Private Cloud

  • VPC is a private cloud computing environment contained within a public cloud and once can launch AWS resources in.

  • Check in your account if you already have a default VPC and if not, go to the VPC dashboard and create a default VPC.

VPC

Launch an EC2 instance

  • I already have an article that covers launching EC2 but just to touch briefly on the steps:

configurations

  • Under security limit access to your IP address only.

access

  • If you do not have a SSH key be sure to download a new one.

N/B
This key-pair will allow you to log into your instance, using SSH, from your local machine. Save the key-pair carefully, because the same private key cannot be re-generated.

  • Once you have launched your Instance, verify that it is running successfully.

Create an IAM Role

Identity and Access Management is used to specify who and what can access services and resources in AWS.

  • On the IAM dashboard, select Roles
  • Click on Create role button

create role

  • Select AWS service as the trusted entity and EC2 as the use case. This will allow the instance to whom the role will be attached to to be able to call any AWS service on your behalf.

role1

  • Under the permissions, search for AdministratorAccess in Filter policies textbox to apply to the role.

permissions

  • Under the review section, provide a name to the new role.

role name

Attach the Role to the EC2 Instance

  • On the EC2 dashboard, check on the running instances and select the checkbox on the Instance we created earlier.
  • Click the Actions button which will open a drop-down options, select the SecurityModify IAM role

attach

  • Select and apply the newly created role to your Instance

select role

Connect to your EC2 instance

  • We are going to connect to the EC2 instance using SSH, under Actions, click on Connect

connect

  • Follow the SSH steps to connect to the Instance.

ssh

  • After connecting to the instance, you need to verify installation of AWS CLI

terminal

Conclusion

  • This is a practical method for having a well configured, secure server that you can use for testing without worrying about credentials.

Happy cloud adventures!

Top comments (0)