# Day 40 AWS EC2 Automation ☁

## 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.

Also, if you know a few things, you can automate many things.

Read from [here](https://aws.amazon.com/ec2/)

## 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.
    

Read more from [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html)

## Instance Types:

Amazon EC2 has a large number of instance types that are optimised 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.

Read from [here](https://aws.amazon.com/ec2/instance-types/?trk=32f4fbd0-ffda-4695-a60c-8857fab7d0dd&sc_channel=ps&s_kwcid=AL!4422!3!536392685920!e!!g!!ec2%20instance%20types&ef_id=CjwKCAiA0JKfBhBIEiwAPhZXD_O1-3qZkRa-KScynbwjvHd3l4UHSTfKuigd5ZPukXoDXu-v3MtC7hoCafEQAvD_BwE:G:s&s_kwcid=AL!4422!3!536392685920!e!!g!!ec2%20instance%20types)

## 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 (You can use the Day 39 User data script for installing the required tools.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687063584882/f1979510-d941-4296-b114-74cd7673038f.png align="center")
    
    Selecting the template
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687063731103/313e6045-2928-49d2-8693-53466cfb4571.png align="center")
    
    Key pair and ec2 instance required CPU and Memory
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687063860425/e931b64f-69c3-4772-937c-cf5fb557a8ce.png align="center")
    
    Select the subnet and Security group
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687063990827/46a54dfc-95c0-4619-86be-67e702a21519.png align="center")
    
    in addition to this, you can add the shell script for installing the docker nad jenkins in the instances.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687064424054/51bc2c81-e8f8-4c8d-8af4-99c87c821fa7.png align="center")
    
    Now click on Actions, to launch the instances from the template
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066140204/d9ddfa3f-2519-4526-9372-5208e2f5d1d9.png align="center")
    
    Give the number of instances as like 3.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066164683/bdef1b27-f35e-477c-a305-a5aaa1d1e741.png align="center")
    
* Create 3 Instances using Launch Template, there must be an option that shows the number of instances to be launched, can you find it? :)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066227340/94127766-6a3d-4c55-ab43-b06e86781c46.png align="center")
    
* You can go one step ahead and create an auto-scaling group, sounds tough?
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066304487/82160586-2560-4bb2-9950-f7fd6395797f.png align="center")
    
    what subnet do you want to give to keep the servers at.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066355765/15a43239-b380-4402-a353-1a783dc45ee0.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066384528/86f3fcbc-767d-4f03-851a-710befe1c70f.png align="center")
    
    Now, you have to give the desired capacity and the maximum capacity of the group to create the servers.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066410148/ffd412bd-4998-4a34-8a1f-9904477e2d79.png align="center")
    
    You can review all the details of the Autoscaling group
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066433969/bbc5bbd6-96a2-4847-b002-e4c23db21750.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066459778/ef9c04a6-43bf-46c6-ac49-9a9ec4416d5a.png align="center")
    
    Finally, you can see that the six instances has been added.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687066681920/6ee96fb1-bd48-457c-b9ca-22ce9725b7c9.png align="center")
    

Check [this](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-template.html#create-launch-template-for-auto-scaling) out

Post your progress on Linkedin.

Happy Learning :)
