Mastering AWS Basics : IAM User Creation and EC2 Instance Setup

Mastering AWS Basics : IAM User Creation and EC2 Instance Setup


Introduction

Amazon Web Services (AWS) is a comprehensive and widely adopted cloud platform, offering over 200 fully featured services from data centers globally.

Today, we'll explore the basics of AWS, focusing on Identity and Access Management (IAM) and launching EC2 instances.

This guide will walk you through creating IAM users, assigning permissions, and setting up a Linux instance with Jenkins and Docker.

Understanding AWS IAM

AWS Identity and Access Management (IAM) allows you to manage access to AWS services and resources securely.

IAM enables you to create and manage AWS users and groups and use permissions to allow and deny their access to AWS resources.

This ensures that the right people have the right access to perform their tasks.

Learn more about IAM:


Task 1: Creating an IAM User and Launching an EC2 Instance

Step-by-Step Guide:

  1. Create an IAM User:

    • Sign in to the AWS Management Console.

    • Open the IAM console at IAM Console.

    • In the navigation pane, choose Users and then Add user.

    • Enter a username and select Programmatic access to generate an access key ID and secret access key.

    • Click Next: Permissions and choose Attach existing policies directly.

    • Select the AmazonEC2FullAccess policy.

    • Review and create the user. Download the .csv file containing the user's credentials.

  2. Launch an EC2 Instance:

    • Sign in to the AWS Management Console.

    • Open the EC2 console at EC2 Console.

    • Choose Launch Instance.

    • Select an Amazon Machine Image (AMI), such as Amazon Linux 2 AMI.

    • Choose an instance type, such as t2.micro (eligible for the free tier).

    • Configure instance details and add storage.

    • In the Configure Security Group step, create a new security group or select an existing one to allow SSH access.

    • Review and launch the instance, creating a new key pair or selecting an existing one.

    • Connect to your instance using SSH.

  3. Install Jenkins and Docker via Shell Script:

    • Connect to your EC2 instance using SSH.

    • Create a shell script to install Jenkins and Docker:

        #!/bin/bash
        # Update the package repository
        sudo yum update -y
      
        # Install Java (Jenkins dependency)
        sudo amazon-linux-extras install java-openjdk11 -y
      
        # Install Jenkins
        wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
        sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
        sudo yum install jenkins -y
        sudo systemctl start jenkins
        sudo systemctl enable jenkins
      
        # Install Docker
        sudo amazon-linux-extras install docker -y
        sudo systemctl start docker
        sudo systemctl enable docker
        sudo usermod -aG docker ec2-user
      
        echo "Jenkins and Docker installation completed."
      
    • Save the script and run it:

        chmod +x install_jenkins_docker.sh
        ./install_jenkins_docker.sh
      

Task 2: Creating a DevOps Team of Avengers

Step-by-Step Guide:

  1. Create IAM Users:

    • Open the IAM console.

    • Choose Users and then Add user.

    • Create three users named after Avengers (e.g., IronMan, CaptainAmerica, Thor) with Programmatic access.

    • Attach the necessary policies, e.g., AmazonEC2FullAccess.

  2. Create a DevOps Group and Attach Policies:

    • In the IAM console, choose Groups and then Create New Group.

    • Name the group DevOpsAvengers.

    • Attach the AmazonEC2FullAccess policy to the group.

    • Add the created users to this group.

Conclusion

By following this guide, you’ve successfully created IAM users, launched an EC2 instance, and installed Jenkins and Docker using a shell script. Additionally, you’ve formed a DevOps team with IAM policies, illustrating the power and flexibility of AWS IAM in managing access and permissions. Keep exploring AWS to unlock its full potential!

Happy learning and cloud computing! ☁️🚀