Day 39 EC2 User Data and IAM Roles ☁
User Data in AWS:
When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives.
You can also pass this data into the launch instance wizard as plain text, as a file (this is useful for launching instances using the command line tools), or as base64-encoded text (for API calls).
This will save time and manual effort every time you launch an instance and want to install any application on it like Apache, docker, Jenkins etc
Read more here
IAM Roles
IAM (Identity and Access Management) roles in AWS (Amazon Web Services) are a secure way to grant permissions to entities, such as AWS services, users, or applications, to access AWS resources.
IAM roles are different from IAM users in that they are not associated with a specific individual or service account.
Task1:
Launch the EC2 instance with user data to install Jenkins on it. Once the server shows up in the console, hit the IP address in the browser and your Jenkins page should be visible.
Take a screenshot of the Userdata and Jenkins page, this will verify the task completion.
#!/bin/bash
#Install Docker
sudo apt-get update -y
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER
#Install Jenkins
#Jenkins requires Java to run, so first install Java -->
sudo apt-get update -y
sudo apt install openjdk-11-jre -y
#Long-Term Support release of Jenkins---->
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install jenkins -y
docker --version
java -version
jenkins --version
Task2:
Read more on IAM Roles and explain the IAM Users, Groups and Roles in your terms.
IAM is a service provided by AWS that helps us to control access to our AWS resources. In IAM, there are three main entities: IAM users, groups, and roles.
'IAM Users': IAM users are similar to user accounts. They represent individual people or services that interact with your AWS resources. Each IAM user has a unique name and credentials (username and password) or access keys (access key ID and secret access key) for programmatic access. IAM users have their own set of permissions that determine what actions they can perform on AWS resources.
'IAM Groups': IAM groups are collections or sets of IAM users. Instead of assigning permissions to individual users, you can assign permissions to groups. This simplifies permission management, as you can add or remove users from groups to grant or revoke permissions for multiple users at once.
'IAM Roles': IAM roles are a way to grant permissions to entities that are not directly associated with a specific user. Roles are often used by AWS services or applications running within your AWS infrastructure. Roles have policies attached to them that define what actions can be performed and what resources can be accessed. Roles can also establish trust relationships with other AWS accounts or external identity providers, allowing those trusted entities to assume the role and access resources.
Create three Roles named: DevOps-User, Test-User and Admin.
Day 39 task is completed!
90DaysOfDevOps Tasks👇