Thursday 13 May 2021

CREATE EC2 AND CONNECT VIA SSH TELNET

This post provides step-by-step instructions to create an EC2 instance and access the instance via SSH telnet. As a newbie in the AWS world, I struggled a lot to understand vocabulary related to it.

Hope this is helpful and happy learning !!!

----------------------------------------------------------------------------------------------------------------------------------


Steps to create EC2 instance:

1)  Navigate to https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Instances:sort=instanceState.

2) Under the Instance tab in the EC2 dashboard. Go for launch instance and choose the AMI type. Here I am creating a Ubuntu instance.

3) Click next and choose the instance type. I have chosen the free tier here.

Instance Type
EC2 Instance Type

4)  Clik next and I am using the default VPC that is created when your AWS account is created and select any one of the subnets in which you want to launch your instance.

Instance Details
EC2 Instance Details


5) Clik next and go for “Add Storage”. Here I have chosen the basic volume type and size as default.

Storage
EC2 Storage

6)  Next add tag which is optional, if you have numerous number of instances running then it is better to add a unique tag name for recognition. 

I have added a tag for example.

Tag
EC2 Tag

    7) Then navigate to “Configure Security Group” and add the rule as below which allows any IP address can access the instance. You can SSH instance, if only you add this rule.

Security Group
EC2 Security Group

8) After this, we can “Review and Launch” the instance. While launching the instance create a new key pair or use the existing key pair.

Key pair allows you to connect to your instance securely. 

Accept the terms and condition and download the key pair, it will be in .pem format.

Key Pair
EC2 Key Pair


The instance might take few minutes for up and running.

----------------------------------------------------------------------------------------------------------------------------------

Steps to convert key pair from PEM into PPK format


You have to convert the key pair from PEM format to PPK format to access the EC2 instance.

    1) Open puttygen.exe and load the PEM file.

    2) The type of key to generate should be SSH-2 RSA and the number of bits generated should be 2048.

puttygen.exe
puttygen.exe

3) 
Once the file is imported, go ahead and save the file as private key.

----------------------------------------------------------------------------------------------------------------------------------

Steps to connect to the instance via SSH :

    1) Open putty and use the private IP address of the instance, which will be available under the Networking tab of the instance.

    2) And load converted PPK file under CONNECTION -> SSh ->AUTH. 

Putty
Putty

    3) And click open. Now login with user name as ubuntu, it requires no password.

Ubuntu EC2 Instance
Ubuntu EC2 Instance

    Voila !!! Now you are connected to the instance.

Tuesday 11 May 2021

Creating And Using Lambda Layer in AWS Lambda

You can find how to create a lambda function using EC2 here. Once the deployment package is created and placed in S3 in the bucket.

STEPS TO CREATE LAMBDA LAYER:

Below are the steps to create a lambda layer in AWS.

1) Navigate to Lamdba and choose Layers from Dashboard.

Lambda Layer
Lambda Layer

2) Choose create the layer, mention the layer name, description, Runtimes and select “Upload a file from Amazon S3” and click create. You can also upload the zip file directly from the remote, but the zip file size should be less than 10 MB.

Options to upload Zip file
Options to upload Zip file

3) Click create and copy the ARN of the lambda layer. You can create another version by 'CREATE VERSION' at the top right corner of the Lambda Layer page, by following the same steps as above.

Lambda Layer
Lambda Layer


HOW TO USE LAMBDA LAYER IN LAMBDA FUNCTION:

Below are the steps to add the lambda layer in the desired lambda function.

·    1) Go to the desired lambda function. Click on the Layers and choose the “Add a layer” option.

Add a layer - AWS Lambda
Add a layer - AWS Lambda

2) 
 After that choose “Specify an ARN” option and paste the ARN of the desired lambda layer.

Choose a layer - AWS Lambda
Choose a layer - AWS Lambda

3) 
Click “ADD” and now run the lambda function.

If Below might the error that you may face while using the lambda layer in a function.

    ERROR MESSAGE: No module found

    SOLUTION: Probably because your deployment package doesn't have a proper structure. 

Lambda Layer Structure
Lambda Layer Structure

   ERROR MESSAGE: Task timed out after 3.00 seconds

    SOLUTION: Increase the timeout period, you can increase it up to 15 mins it is under the configuration tab.

Configuration - AWS Lambda
Configuration - AWS Lambda

Monday 10 May 2021

Creating Lambda Deployment Package Using EC2

Lambda Layers: 

An archive containing additional code, such as libraries, dependencies, or even custom runtimes. When you include a layer in a function, the contents are extracted to the /opt directory in the execution environment.

Run the commands mentioned below to create the package for lambda layers in the EC2 server.

The Lambda Layer you are creating should have the below structure or else will get the error message “No module found” while importing the module in lambda function.

Lambda Layer Structure
Lambda Layer Structure

STEPS TO CREATE PACKAGE FOR LAMBDA LAYER:

  1. Create a folder structure as below to install the package for desired modules. 

    mkdir -p build/python/lib/python3.6/site-packages
    

  2. Below three commands are to select the python version to install the modules and to install pip3. (Optional) 

    ls usr/bin/python*
    sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python3.6 1
    sudo update-alternatives --config python3
    sudo apt install python3-pip
    

  3. This command is to install the desired module in the targeted folder. Here I am installing Pandas and xlrd.  

    pip3 install pandas xlrd -t build/python/lib/python3.6/site-packages/ --system
    

    Below commands are to create the zip file for the lambda layer package. 
     

    cd build/
    zip -r9 Python3.6_Pandas_Lib.zip *
    

    That's it now the deployment package is ready. Copy the zip file to the S3 bucket.
--------------------------------------------------------------------------------------------------------------
Here are some other posts that might be helpful :