# #Day 40 AWS EC2 Automation

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709650772631/0002892d-163f-42d4-969b-9dea7a0464b3.png align="center")

### **Automation in EC2:**

Amazon EC2, or Amazon Elastic Compute Cloud, can give you secure, reliable, high-performance, and cost-effective computing infrastructure to meet demanding business needs.

### Launch template in AWS EC2:

* You can make a launch template with the configuration information you need to start an instance. You can save launch parameters in launch templates so you don't have to type them in every time you start a new instance.
    
* For example, a launch template can have the AMI ID, instance type, and network settings that you usually use to launch instances.
    
* You can tell the Amazon EC2 console to use a certain launch template when you start an instance.
    

### Instance Types:

Amazon EC2 has a large number of instance types that are optimized for different uses. The different combinations of CPU, memory, storage and networking capacity in instance types give you the freedom to choose the right mix of resources for your apps. Each instance type comes with one or more instance sizes, so you can adjust your resources to meet the needs of the workload you want to run.

### AMI:

An Amazon Machine Image (AMI) is an image that AWS supports and keeps up to date. It contains the information needed to start an instance. When you launch an instance, you must choose an AMI. When you need multiple instances with the same configuration, you can launch them from a single AMI.

### Task1:

**Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup.**

* Open the Amazon EC2 interface.
    
* Choose "Launch Templates" from the left navigation pane.
    
* Choose "Create launch template" to start.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709650923765/83b72409-82ad-448c-8626-7b6cdd002340.png align="center")

* Give the launch template a name on the "Create a launch template" tab.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709650990554/468f1e0a-37b5-405d-a18e-9ab714e0ed7e.png align="center")
    
    * Choose "Amazon Linux 2" under "Amazon Machine Image (AMI)"
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQHhwY70YQZ8HQ/article-inline_image-shrink_1500_2232/0/1678773655586?e=1713398400&v=beta&t=lCEpgUKS0vjxgez8wUiJ6in48Y1_1zUE1sseyzR0Dwc align="left")
    
    * For "Instance type", choose "t2.micro"
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQH7Fkb8Vv_h8w/article-inline_image-shrink_1500_2232/0/1678773719236?e=1713398400&v=beta&t=EeV027fTYAUkkEB-So25UHlalBirNo5DA1FcsssaKYo align="left")
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQHHFEonL347Pw/article-inline_image-shrink_1500_2232/0/1678773779163?e=1713398400&v=beta&t=IAkSBJNWPb4p4mjGTrfewnYMRsHQ1VRAyCH85_bm2hY align="left")
    
    * Paste the user data script for installing Jenkins and Docker in the "User data" field of the "Advanced Details" section.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQG-jdc0O3_27A/article-inline_image-shrink_1500_2232/0/1678773854635?e=1713398400&v=beta&t=a9ZvSw0u_-I4xoCX9gBK1QrSY9gkdnncQhMKgXGZgCs align="left")
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQEMuhCXlhUfHA/article-inline_image-shrink_1500_2232/0/1678773866459?e=1713398400&v=beta&t=T_Bs4plyWXPXi1LGj42ew0cMF-2ALC_BJA7FHII-cC0 align="left")
    
    * Choose "Create launch template" to start. The produced template is shown below.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQF3rPnqGLorbg/article-inline_image-shrink_1500_2232/0/1678773931487?e=1713398400&v=beta&t=nr-ROLOATFoZOv8Fa-RRqb4JaS5rvFSSf5jxFWRmDHM align="left")
    
    **Build 3 instances using the Launch Template; can you locate the option that displays the number of instances to be launched?**
    
    * To use the launch template to launch three instances
        
    * Choose "Launch instance from templates" in the left navigation pane of the Amazon EC2 dashboard.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQF0XheOFqxKFA/article-inline_image-shrink_1500_2232/0/1678774014118?e=1713398400&v=beta&t=GhYQ6PzGZadLSl4sVCwbjm92i4fZhrXidxU_3mgFgz4 align="left")
    
    * Choose the newly built launch template.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQH5UiTDSOFzwA/article-inline_image-shrink_1500_2232/0/1678774463276?e=1713398400&v=beta&t=T3gETHBViqd7Eoncv-ACfvxRfeMp1IDT1ipeYSsNBbg align="left")
    
    * Enter the desired number of instances in the "Number of instances" field on the right side. Choose the other setup options, such as VPC, subnet, security group, and so forth, as desired.
        
    * To start the instances, select "Launch instances."
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGMP71xVxHWAg/article-inline_image-shrink_1500_2232/0/1678774604451?e=1713398400&v=beta&t=RhUHn6Z9SyCN1JFs184F0tKyrQU_z5qBf-WkBOoJ3YE align="left")
    
    * Three instances made from a template are seen.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQHoWDtMGwWAcw/article-inline_image-shrink_1500_2232/0/1678774686802?e=1713398400&v=beta&t=sQ6-GOHJKof0bWOUqlAiRX7SBuOsIL-Ndw67qifqqlM align="left")
    
    **You may take it a step further and make an auto-scaling group.**
    
    * Choose "Auto Scaling Groups" from the left navigation pane.
        
    * "Create Auto Scaling Group" should be selected.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFQ-z9zi6_fWw/article-inline_image-shrink_1500_2232/0/1678774765519?e=1713398400&v=beta&t=oYA1ZBiyj70RVduxzEgmw4jK_l5i5yHFNjB6ZmnktZc align="left")
    
    * Give the auto-scaling group a name on the "Create Auto Scaling Group" page.
        
    * Choose the launch template we made earlier under "Launch Template."
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFonIfWbQa1gg/article-inline_image-shrink_1500_2232/0/1678774844356?e=1713398400&v=beta&t=kyuVYRu6_iDrOIm176VDjeuy8f9jhBedargigCoceWM align="left")
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGE3QVAjvW8sw/article-inline_image-shrink_1500_2232/0/1678774867954?e=1713398400&v=beta&t=gYjo-2xh6IGmj4WSWupGGm736MTqO0iF4mGqDB3JpnU align="left")
    
    * Choose the VPC and subnet you want the instances to launch in under "Network".
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFUmyJd4eIq5A/article-inline_image-shrink_1500_2232/0/1678774958218?e=1713398400&v=beta&t=8shC5W38KTa883Zb6gfyOWrG8-9pa0jZHkorFCc9dAs align="left")
    
    * Choose any option for "Load balancing" depending on your needs.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQEp5fXj9EpSZg/article-inline_image-shrink_1500_2232/0/1678775093699?e=1713398400&v=beta&t=auICnLNBPzFFU_ev9F4sq3lPUU9m1zQ4V0drcliu4r8 align="left")
    
    * Enter the desired capacity for the auto-scaling group on the "Group Size" tab, for example, 2.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGsAwxkucdxzQ/article-inline_image-shrink_1500_2232/0/1678775148724?e=1713398400&v=beta&t=k86FN_H7iLD1DUmjHnSgEscGi7HgGvdx3J-0_j371M8 align="left")
    
    * You can select to set up scaling strategies for "Scaling policies" based on several metrics like CPU use, network in/out, and others. Choose the tracking policy for the policy objective.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQHUyFtZH4P9Ww/article-inline_image-shrink_1500_2232/0/1678775208104?e=1713398400&v=beta&t=ZyHvOpAyRZILf8WGz-WXkMC6I-TlGAD2-R1cy51vNuI align="left")
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGWKVH507EiIA/article-inline_image-shrink_1500_2232/0/1678775240227?e=1713398400&v=beta&t=Xm0vKUvQACAua0ElVGFoDSNth4_UvPFin3kMWBzgm5o align="left")
    
    * To build the auto-scaling group, select "Create Auto Scaling Group".
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFB3gZM7WKOUw/article-inline_image-shrink_1500_2232/0/1678775293263?e=1713398400&v=beta&t=-e7_-VRYK2oVqQzQnMILvMsKizuBhgK67H6XFoLJjx8 align="left")
    
    * An autoscaling group is created.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQG7p4VsBoMoug/article-inline_image-shrink_1500_2232/0/1678775332442?e=1713398400&v=beta&t=hbRZyqAfExcPIC9M6tz57J3TR1xCa5yh-ojWNWcoLqM align="left")
    
    * Based on the launch template and parameters you specified, the auto-scaling group will launch the required number of instances within a short while. The auto-scaling group launched the two new instances below.
        
    
    ![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFaN3Bc00UrVw/article-inline_image-shrink_1500_2232/0/1678775433530?e=1713398400&v=beta&t=-ZjpgqRiKhI56ZvVjo0PQWRhzWkJlZeGt-C9SmNgOz8 align="left")
    
    Thankyou
