Blogs  

How to Launch an EC2 Instance Using a Custom AMI

How to Launch an EC2 Instance Using a Custom AMI

Cloud computing follows the Agile software development lifecycle, enabling rapid server deployment and scalability. For instance, Netflix utilizes AWS EC2 with Autoscaling to automatically add or remove instances based on user demand. In this article, we’ll explore how to launch an EC2 instance using a custom AMI.

Naresh I Technologies is the number one computer training institute in Hyderabad and ranks among the top five computer training institutes in India. Contact us for comprehensive AWS training today!

Ways to Deploy Applications on an EC2 Instance

There are several ways to get your application and its settings onto an EC2 instance:

  1. Configuration Management Tools: Tools like Chef and Puppet allow lifecycle management of applications (install, upgrade, rollback) on thousands of machines.
  2. User Data Scripts: Pass shell scripts to the EC2 instance to install and configure applications during startup.
  3. Custom AMI: An Amazon Machine Image (AMI) includes all necessary details like OS, applications, and settings. It is the quickest method to launch an EC2 instance.

Below, we detail the steps to create a custom AMI and launch an EC2 instance using it.

Steps to Launch an EC2 Instance Using a Custom AMI

Step 1: Launch an EC2 Instance Using an Existing AMI

  1. Use an existing Linux or Windows AMI to launch an EC2 instance.
  2. Log in to the instance (e.g., using PuTTY for Windows).

Step 2: Install the Required Application

Install your desired application and make configuration changes. For example, install Apache Tomcat on an Ubuntu EC2 instance:

sudo apt update  
sudo apt install tomcat9  
sudo systemctl start tomcat9  
  • Verify the installation: Access http://ec2-public-ip:8080 in a browser.
  • Ensure port 8080 is open in the Security Group’s inbound rules.

Step 3: Create a Custom AMI

  1. Stop the EC2 Instance: Ensures consistency during image creation.
  2. In the AWS Management Console, navigate to:
    • ActionsImageCreate Image.
  3. Provide the Image Name and Description.
  4. Restart the instance after the image is created.
  5. Navigate to the AMI tab in the left panel to monitor its status.
    • The AMI starts in a pending state and changes to available.

Visibility Settings: By default, the AMI is private. You can make it public or share it with specific users:

  • ActionsManage Image Permissions.

Step 4: Launch a New EC2 Instance Using the Custom AMI

  1. Go to the EC2 Management ConsoleLaunch Instance.
  2. Under My AMIs, select the custom AMI created earlier.
  3. Follow the standard EC2 instance launch process.
  4. Verify your application (e.g., Tomcat) by accessing the instance’s public 

    http://ec2-public-ip:8080
    


    Important Notes
  1. Deregister the AMI: Once the EC2 instance is terminated, deregister the AMI to avoid unnecessary storage costs.
  2. Terminate Unused Instances: If an EC2 instance remains active, it incurs costs even if unused.

Why Use a Custom AMI?

Creating a custom AMI simplifies deployment:

  • Faster Launch: Applications and configurations are pre-installed.
  • Consistency: Launch identical instances every time.
  • Scalability: Ideal for Autoscaling environments.

Learn AWS at Naresh I Technologies

Naresh I Technologies offers comprehensive AWS training for freshers and professionals. As the number one computer training institute in Hyderabad, we provide:

  • Classroom and Online Training
  • Hands-on Practical Sessions in world-class labs
  • Corporate Training with theoretical and practical modules
  • Job Placement Assistance for freshers

Start your AWS journey today! Contact us by submitting the online form on our website or giving us a missed call. Our counselors will guide you in choosing the right AWS certification.

Naresh I Technologies – Shaping Careers, Building Futures!
Contact us today for expert AWS training.

 

 

Guide to AWS Serverless Computing- AWS Lambda

AWS Lambda Tutorial

AWS Lambda is a compute service offered by Amazon Web Services (AWS). Unlike EC2, Elastic Beanstalk, or OpsWorks, Lambda is designed to simplify the development and execution of code without the need to manage servers or underlying infrastructure. Below, we’ll explore what AWS Lambda is, how it works, and its use cases.

What is AWS Lambda?

AWS Lambda is a serverless compute service that allows developers to run code without provisioning or managing servers. With Lambda, you only need to provide the code, and AWS handles the infrastructure, scaling, and resource management automatically.

Key Benefits of AWS Lambda:

  • Focus solely on writing and deploying application code.
  • AWS handles launching, scaling, patching, and updating resources.
  • Ideal for event-driven applications or tasks with variable workloads

Where to Use AWS Lambda

AWS Lambda is best suited for event-driven tasks, where specific triggers initiate the execution of code. For example:

  • Backend processing for web and mobile applications.
  • Image processing, such as resizing, filtering, or compression.
  • Automated data processing tasks triggered by changes in a database or object storage (e.g., S3 buckets).

How AWS Lambda Works

Lambda functions are triggered by event sources such as file uploads, database updates, or HTTP requests. Let’s walk through an example where an image upload to an S3 bucket triggers a Lambda function:

  1. Event Trigger: A user uploads an image to an S3 bucket.
  2. Notification Setup: The S3 bucket has a notification configured to trigger a Lambda function.
  3. Lambda Execution Role: IAM (Identity and Access Management) roles provide Lambda the necessary permissions to access resources (e.g., S3).
  4. Code Execution: The Lambda function executes tasks such as resizing or filtering the uploaded image.

Why Choose AWS Lambda?

When architecting solutions, you have several compute options:

  1. AWS EC2:
    Requires manual setup and management of virtual machines, software, and infrastructure.
  2. AWS Elastic Beanstalk:
    Best for deploying full applications, not suitable for backend-only tasks.
  3. AWS OpsWorks:
    Focuses on application lifecycle management, which may not be needed for simple backend tasks.
  4. AWS Lambda:
    A lightweight, serverless option where you only upload your code, and AWS handles everything else.

Example Use Case:

  • News Feed Processing:
    • During high traffic (e.g., mornings), Lambda scales to handle spikes.
    • During low traffic (e.g., nights), Lambda incurs no cost due to inactivity.
    • However, for continuously running workloads, EC2 might be a better choice.

Limitations of AWS Lambda

While Lambda is powerful, it has some architectural and hardware limitations:

  • Disk Size: Limited to 512 MB.
  • Memory: Configurable between 128 MB and 1536 MB.
  • Execution Timeout: Maximum of 15 minutes.
  • Request Payload: Maximum size of 6 MB for synchronous requests and 128 KB for event payloads.

Pricing

AWS Lambda follows a pay-as-you-go model:

  1. Number of Requests:
    • First 1 million requests are free.
    • $0.20 per 1 million requests thereafter.
  2. Execution Time:
    • Calculated based on memory allocation and execution duration.
    • $0.00001667 per GB-second of usage.

Creating a Lambda Function

Here’s a step-by-step guide to creating a Lambda function that logs a message when an object is added to an S3 bucket:

  1. Navigate to AWS Lambda Console:
    Under the "Compute" section in the AWS Management Console, select AWS Lambda.
  2. Create a New Lambda Function:
    Click "Create Function" and select a blueprint (e.g., blank function).
  3. Set the Trigger:
    Choose S3 as the trigger source and specify the bucket and event (e.g., object creation).
  4. Configure the Lambda Function:
    • Provide a name and description for the function.
    • Select a runtime (e.g., Node.js, Python).
    • Use the inline editor to add the following code:javascript
      Copy code


      exports.handler = (event, context, callback) => {
    •     console.log("An object added to S3");
    • };



    • Set up an execution role with appropriate permissions (e.g., S3 object read-only access).
  5. Deploy and Test:
    • Upload a file to the specified S3 bucket.
    • Verify that the Lambda function logs the event in CloudWatch.

Conclusion

AWS Lambda simplifies application development by eliminating the need to manage infrastructure. It’s ideal for event-driven applications, variable workloads, and automating backend processes. However, for long-running or continuous workloads, EC2 might be a better fit.

About Naresh I Technologies:


Naresh I Technologies is the number one computer training institute in Hyderabad, ranking among the top five institutes in India. We provide comprehensive AWS training, including practical labs and real-world projects. Whether you’re a fresher or a professional, our AWS certification courses cater to all levels. Contact us today to start your AWS training journey!

How to Restore EC2 with the Help of the Snapshot

How to Restore an EC2 Instance Using a Snapshot

AWS offers powerful cloud services like EC2 (Elastic Compute Cloud) for scalable computing and S3 (Simple Storage Service) for efficient storage. Among these, creating and restoring backups is crucial for disaster recovery and business continuity. This article focuses on how to restore an EC2 instance using an EBS snapshot.

What Are EC2 and S3?

EC2 is a compute web service allowing users to run virtual servers (instances) for applications. These instances come preconfigured with popular operating systems or can be customized based on specific needs.

S3 is AWS's scalable storage solution, enabling object-based storage via a user-friendly web interface. Together, EC2 and S3 form the backbone of many AWS-powered applications.

 

What Is an EBS Volume?

EBS (Elastic Block Store) is block-level storage designed for use with EC2 instances. It supports scenarios where frequent data updates, long-term data persistence, or high read/write operations are required. EBS is the go-to choice for database applications due to its reliability and scalability.

What Is an EBS Snapshot?

An EBS snapshot is a point-in-time backup of EBS volumes, stored in Amazon S3. Snapshots are incremental, meaning only the changes since the last snapshot are saved, reducing time and storage costs. These snapshots are critical for restoring EC2 instances in case of errors or data loss.

Steps to Restore EC2 from a Snapshot

Follow this step-by-step guide to create, delete, and restore an EC2 instance using snapshots:

Step 1: Launch an EC2 Instance

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 dashboard and click on Launch Instance.
  3. Choose an Amazon Machine Image (AMI), such as Ubuntu or Windows Server.
  4. Select an instance type like t2.micro (free-tier eligible).
  5. Configure instance details, such as network and subnets.
  6. Add storage (e.g., 8 GiB of SSD).
  7. Add tags for easy identification.
  8. Create a security group and define rules.
  9. Review configurations, generate a key pair, and launch the instance.

 

Step 2: Create and Modify a File for Verification

  1. Access the instance via SSH or PuTTY.
  2. Create a directory (e.g., NareshText) and a file (e.g., NareshFileText.txt).
  3. Add content to the file for verification purposes.

Step 3: Create an EBS Snapshot

  1. In the EC2 dashboard, select the instance associated with the EBS volume.
  2. Click on Actions > Create Snapshot.
  3. Provide a description for the snapshot and save it.

Step 4: Terminate the EC2 Instance

  1. Terminate the EC2 instance after ensuring the snapshot has been created successfully.

Step 5: Restore EC2 from Snapshot

  1. Navigate to the Snapshots section in the AWS Console.
  2. Create an AMI (Amazon Machine Image) from the snapshot:
    • Select the snapshot.
    • Click Create Image and provide a name and description.
  3. Launch an EC2 instance using the newly created AMI:
    • Follow the standard instance creation steps.
    • Ensure the configuration matches the previous instance.

Step 6: Verify the Restored Instance

  1. Access the newly created instance.
  2. Navigate to the directory and file created earlier (e.g., NareshText/NareshFileText.txt).
  3. Verify the contents to confirm a successful restoration.

Why Choose Naresh I Technologies for AWS Training?

Naresh I Technologies is a leading provider of AWS training, offering comprehensive courses tailored to various certifications like Cloud Engineer, Solution Architect, and SysOps Engineer. Here's why students and professionals trust us:

  • Expert-Led Training: Learn from certified professionals with real-world experience.
  • Hands-On Practice: Gain practical knowledge through interactive labs.
  • Flexible Learning Options: Choose between online and in-person training sessions.
  • Job Assistance: Receive dedicated support for job placement in top global companies.
  • State-of-the-Art Facilities: Train in fully equipped computer labs designed for immersive learning.

Contact Naresh I Technologies today to enroll in AWS courses and take the next step in your cloud computing career. Whether you're a beginner or an experienced professional, our programs are designed to help you succeed.