Trending March 2024 # Host Dynamic Website Using Aws Ec2 Instance # Suggested April 2024 # Top 12 Popular

You are reading the article Host Dynamic Website Using Aws Ec2 Instance updated in March 2024 on the website Moimoishop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Host Dynamic Website Using Aws Ec2 Instance

This article was published as a part of the Data Science Blogathon.

Introduction on EC2

In this article, we will learn how to host a dynamic website using an . Many will create a dynamic website and will confuse about where to host it and how to host it. In this article, I will help you guys for hosting them.

Amazon Elastic Compute Cloud is a web-based service that allows us to run our applications in the Amazon Web Service (AWS).

What is EC2?

Amazon EC2 uses the AWS Management Console, the AWS Command Line Interface (CLI), or AWS Software Developer Kits (SDKs) for scaling according to changes needed for the end-user, and finally, it will be simple to deploy virtual servers and also to maintain storage and also makes it simple to deploy virtual servers and also to maintain storage.

Features of Amazon EC2

The features that are provided by the Amazon EC2 are,

    It provides instances

    It has multiple templates with software configurations. These are known as Amazon Machine Images( AMIs).

    Instance types include CPU configurations, storage, memory, and also the networking capacity of the instance.

    Key pairs provide secure login information.

    Temporary data such as data that was deleted is known as instance store volumes

    Multiple physical locations are available across the globe

    For dynamic cloud computing, the static IPv4 addresses are known as Elastic IP Addresses and many more.

    Instance: Instance is a virtual server that is launched using the Amazon EC2 service.

    We are hosting this instance using a free tier, yet let’s see the pricing of an EC2 instance.

    It works on a pay as you go and so you have to pay for only what you have used. This instance runs at a cost of $0.192 per hour. For one year it will cost $530 upfront and $44.15 per month and the total is about $1,060.

    Types of Instances

    We can choose different Amazon EC2 instances based on the requirements for our application and also the workload.

    1.

    2. Memory Instances: To process larger datasets with a fast speed, these memory instances are

    5. Storage Instances: When we deploy applications that require high storage requirements, we used storage instances.

    Now let’s see the benefits of Amazon EC2.

    Benefits of EC2

    1. Scalability: Amazon EC2 provides high scalability so when needed we can add instances and we can adjust them according to the demand.

    2. Security: EC2 has several built-in security features which make you feel comfortable using EC2.

    3. Flexibility: it provides you to choose multiple types of instances, various software packages, os, and instance storage.

    4. Cost-effective: It is very cost-effective. We have to pay only for what we have used.

    5. Computing Capacity: It provides a secure and resizable compute capacity.

    6. Reliable: These services are very reliable. Here we can do replacement of instances very easily and rapidly.

    7. Servers in Multiple Regions: These services are available in multiple regions across the globe. So we can prefer locations near to us.

    Hope you have gained some knowledge of EC2. Now let’s move on to the hosting part.

    Hosting Website

    For hosting first, you have to be ready with all your files and make them in one folder.

    Next Log in to AWS.

    Select Root User and enter the mail with which you have created the AWS account.

    Captcha and then enter the password finally to successfully log in.

    After that select the region near to your place and also the region where the EC2 service is available. And then search for EC2 and open it.

    Now there will be steps. those are:

    1. Choose AMI

    2. Choose Instance Type

    3. Configure Instance

    4. Add Storage

    5. Add Tags

    6. Configure Security Group

    7. Review

    Let’s come one by one.

    The first one is choosing Amazon Machine Image (AMI).

    Before launching an instance we have to select it. Amazon Machine Image (AMI) provides all the information that is required for you to launch an instance. Using a single AMI you can launch multiple instances. It is useful when you need to launch multiple instances of the same configuration.

    Amazon Machine Image (AMI) is like a template that contains software configuration. Examples include an operating system, application servers, and like applications.

    Here I have selected Microsoft Windows Server 2023 Base.

    We can select whatever we want.

    Next, choose an instance type.

    Next, Configure the instance.

    Next is adding storage.

    And 5th step is adding tags.

    Next, Configure Security Group.

    Here for security purposes, we have to add two RDPs. They are HTTP and HTTPS.

    Check everything if it is ok and then Launch.

    Now we have to select key pair. Create one new key pair with any name and then download Keypair.

    Then go to view instances and wait till the status check turns to 2/2 checks passed.

    Then it will download the remote desktop.

    Now go to the search bar on your local desktop and search for Remote Desktop connection. And for computers paste the public DNS and then connect.

    Enter username and Password by copying from RDP Client and then press OK.

    Open internet explorer and download the Xampp

    And Now open File Explorer on your Remote Desktop. In C drive you will find the Xampp folder and in that open the htdocs folder and in that paste the folder in which all your files related to the website were saved. Rename its dashboard. Before that rename the folder which is named dashboard to some different name.

    Now go to that Xampp server.

    Your website has been hosted successfully now. To view it you can search Public DNS on any browser and on any desktop either its local or Remote desktop.

    Conclusion on EC2

    This is how you can host your dynamic website using the Amazon EC2 instance. Using this EC2 instance we can host our dynamic website very simple than we expected. If you are just practising how to host the website with the Free en don’t forget to terminate the instance once you are done. Else Amazon will charge you for what you have used. Overall in this article, we have understood

    Hope you guys found it useful.

    Connect with me on LinkedIn

    The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

    Related

    You're reading Host Dynamic Website Using Aws Ec2 Instance

    Creating And Deploying Using Aws Cli

    Creating and Deploying using AWS CLI

    AWS CLI is a command line tool which helps to work with AWS services. We can use it to create, update, delete, invoke aws lambda function. In this chapter, you will discuss about installation and usage of AWS CLI in detail.

    Installation of AWS CLI

    This section will guide you through the installation of AWS CLI on various operating systems. Follow the steps given and observe corresponding screenshots wherever attached.

    For Windows

    Check your Windows configuration and choose one of the following links for installing AWS CLI MSI −

    Next, set the Environment path in windows as shown in the screenshots below −

    Once done, you can use the following command on the command prompt, to see if aws cli is installed −

    aws --version

    It displays the details of aws-cli version as shown in the following screenshot −

    For Linux / Mac

    For installing on Linux and Mac, you need Python 2.6.3 or higher verison of it. Then, use following commands for further installation processes −

    $ unzip awscli-bundle.zip $ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

    Now, we need to configure AWS settings. You can use the following command for this purpose −

    aws configure

    For this purpose, it requires details such as −

    AWS Access Key ID

    AWS Secret Access Key

    Default region name

    Default output from format

    You can obtain these details from your aws console. Go to you Account name at top right corner as shown −

    Add the user and to get the access key and secret key. To see the new access key, choose Show. Your credentials will look like as shown below −

    Access key ID − AOSAIOSFOCDD7Example

    Secret access key − aJuirCVtnROUN/K7MDENG/bPxRfiCYExampleKEY

    Reference Commands for AWS CLIS

    The following table will give command references available to work with aws cli.

    Name of aws cli command Command reference

    create-function

    list-functions

    get-function

    get-function-configuration

    get-account-settings

    update-function-configuration

    update-function-code

    delete-function

    Now, let us discuss these commands one by one in detail.

    create-function

    This api will create a new lambda function. The code needs to be given in zip format. If the function to be created already exists, the api will fail. Note that the function name is case-sensitive.

    Commands Included

    The list of commands that you can use with create-function is given here −

    create-function Options Included

    Various options that you can use with the functions above are as follows −

    –function-name (string) − This takes the name of the function. The name can be 64-bit characters.

    –runtime(string) − Here you need to specify the runtime environment ie the language selection. The details of the runtime are as given below −

    Options available runtime

    Python v3.6 python3.6

    Python v2.7 python2.7

    NodeJS v6.10 nodejs6.10

    NodeJS v8.10 nodejs8.10

    Java java8

    C# 1 dotnetcore1.0

    C# 2 dotnetcore2.0

    Go go1.x

    –role(string) − This will be the name of the lambda policy ie the role to be given to the lambda function for accessing other services. It will have the permission as per the role specified.

    –handler (string) − This is the name of the handler where the lambda code execution will start.

    For nodejs, handler name is the module name that we export.

    For java, it is package.classname :: handler or package.classname

    For python, handler is nameofthefile.

    –code (structure) −AWS Lambda code

    –description (string) − description for the AWS Lambda function

    –timeout (integer) − timeout will have the time at which the lambda function has to terminate execution. The default is 3s.

    –memory-size (integer) − This is the memory given to the aws lambda function. AWS will allocate the amount of CPU and memory allocation based on the memory given.

    –environment (structure) − its a object with environment details required in the aws lambda function.

    e.g : Variables = {Name1 = string, Name2 = string}

    –kms-key-arn (string) − this is amazon resource name (ARN) used to encrypt the environment variables. If not provided it will take the default settings to encrypt.

    –zip-file (blob) − path of the zip file which has the details of the code.

    –cli-input-json (string) : Performs service operation based on the JSON string provided. The JSON string follows the format provided by –generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values.

    Now, let us create a simple AWS Lambda function using runtime as nodejsand add some chúng tôi to be printed.

    Consider a sample code for understanding the same −

    console.log("Using aws cli"); return 'Hello from Lambda from aws cli!' };

    Now, zip the file and store it as chúng tôi .

    Getting ARN

    For the role, let us use the arn from the existing role we have created. To get the ARN, you will have to follow the steps as shown here. Observe the respective screenshots wherever attached −

    Step 1

    Go to IAM and select the role you want from Roles. The ARN details for the role are displayed as shown below. Use Role ARN with create-function in aws cli.

    Observe here that the role arn is : arn:aws:iam::625297745038:role/lambdaapipolicy

    The command with values for create-function is as follows −

    aws lambda create-function --function-name "awslambdausingcli" --runtime "nodejs8.10" --role "arn:aws:iam::625297745038:role/lambdaapipolicy" --handler "awscli.handler" --timeout 5 --memory-size 256 --zip-file "fileb://awscli.zip"

    Now, if you run the command in aws cli, you can find an output as shown below −

    In AWS console, the Lambda function is displayed as shown below −

    The details of the functions are as shown here −

    The details of the configuration are as given below −

    You can test the function and check the output as shown −

    The corresponding Log output is shown here −

    list-functions

    This api gives the list of functions created so far in AWS Lambda.

    Commands Included

    The following are the commands asscociated with this API −

    list-functions Options under list-functions

    The following are various options you can use under this list-functions api −

    –master-region(string) − optional. The region from which the functions needs to be displayed.

    –function-version(string) − optional. This will give the function version.

    –max-items(integer) − optional. This will give the items as the per the value specified.

    –cli-input-json(string) − optional. Will perform operation based on the json file provided.

    The command with values list-functions is as follows −

    aws lambda list-functions --max-items 3

    The command displays details as follows −

    get-function

    This api will give details of the functions and also a url link which has zip file uploaded using create-function. The url with zip details will be valid only for 10 mins.

    Commands Included

    The following are the commands associated with this api −

    get-function Options Included

    –function-name − Name of the AWS Lambda function. You can also specify Amazon Resource Name of the function.

    –qualifier(string) − Optional. Function version can be used to get the details of the function.

    The command with values to get-function are −

    aws lambda get-function --function-name awslambdausingcli

    The command display details are as follows −

    It gives the url which has the zip code uploaded. In the above case the url is −

    https://prod-04-2014- -4ed9-99d9-acb00d2063d2?versionId=d04HKvPu9S2zz8pzjbW6Rmf5o5fxnc_r&X-Amz-Security -Token=FQoDYXdzEKT%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDCpTmGvtwKToPBiWcyK3A96UcJEnwvYDhMbbxu %2Bg2gffK2ocfnlEeiCHak8QqqE1RFpbKrdks9NzxP9gNbagL4M9RValxJ1a9PUY%2FOdAekscRHOiX00MVAxUlI8 2pKryhdOwLJWSj0uRzqvOxCcBwJenHrSNPeG6lMa2ZDo0qZFEUDONSaTg4nuSnJK1f6t3pMAKu4vF9wPvf92G%2BU 60rUxwleggigISmD9l1IlZse3%2BVF1JlNuN%2F5d85v0y2Q%2F%2BO515CybcZpn91sHPYG8JMJ00LsrkQ2Ww4VU 9Zz5c5QYH4JYPj0CyEgSz9b%2FMceMPpOoPUAMjctb%2FEwQqcShZeqAr9%2Fcd2ZI%2BXl2%2Bs4ri0ucgPvQQvs eGIIiZbX3GqdwR2jb1nylrAEIfiuFMoSWfcFYoYtuL0MZnjGR9jy2GNkp6MB%2BlHHr7%2BnuFRUzU26rgDYmdE1w Rb3%2B21Jm49WGDa9opRLvUxFaux57Or70haib2FuKzN6Gf3Vzzk5KPdWsYUpaLyf%2B1ovEytOZhB1JEXuCs%2FG IlOXS88yxT%2BpOKmyxweiezpGgI%2FAkSAQTbSRsYQKIOFyIJNHzplwrJKhy28vy60numIBIo9Zqq2AU%3D &X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240527T112426Z&X-Amz- SignedHeaders=host&X-Amz-Expires=600&X-Amz- Credential=ASIAICSQHLSBWFP37U4Q%2F20240527%2Fus- east-1%2Fs3%2Faws4_request&X-Amz-Signature= 8b97e7d6d7da13313068e027894d2c875be5e50a0c5a62550f55307985bdc1aa get-function-configuration

    This will give the configuration details of the AWS Lambda function.

    The following are the commands used along with this api −

    get-function-configuration

    The following are the options used with

    –function-name (string) − name of the aws lambda function. You can also specify Amazon Resource Name of the function.

    –qualifier(string) − Optional.Function version can be used to get the details of the function.

    The command with values to get-function are −

    aws lambda get-function-configuration --function-name awslambdausingcli

    The command displays details as follows −

    get-account-settings

    This api gives the accounts settings.

    Commands Involved

    The command that you can use with this api are −

    get-account-settings Options Involved

    You can use the following options with this api −

    –cli-input-json(string) − Performs the service based on the json string provided.

    –generate-cli-skeleton(string) − It prints json output without sending the API request.

    You can use the following command for get-account-settings −

    aws lambda get-account-settings

    You can see the following output when you execute the command given above −

    update-function-configuration

    This api helps to update the configuration details for AWS Lambda function created. You can change the memory, timeout, handler, role, runtime, description etc.

    Commands Involved

    The following are the commands involved in the update-function-configuration api −

    update-function-configuration Options Involved

    The following are the options involved in update-function-configuration api −

    –function-name − name of the aws lambda function

    –role (string) − optional. The ARN of role is needed to be updated.

    –handler (string) − optional. The handler details of aws lambda function.

    –description(string) − optional. Description for the function.

    –timeout(integer) − optional. Time required so that aws lambda function can terminate.

    –memory-size(integer) − optional. This is the memory given to the aws lambda function. AWS will allocate the amount of CPU and memory allocation based on the memory given.

    –environment (structure) − optional. It is an object with environment details required in the aws lambda function.

    e.g: Variables = {Name1 = string, Name2 = string}

    –runtime(string) − Here you need to specify the runtime environment ie the language selection.

    The details of the runtime are shown in the table given below −

    Options available runtime

    Python v3.6 python3.6

    Python v2.7 python2.7

    NodeJS v6.10 nodejs6.10

    NodeJS v8.10 nodejs8.10

    Java java8

    C# 1 dotnetcore1.0

    C# 2 dotnetcore2.0

    Go go1.x

    –cli-input-json (string) − optional. This will perform the operation on the api as specified in the json string provided.

    –generate-cli-skeleton (string) − optional. This will output the JSON skeleton of all details without executing the api. The output can be used as a input to –cli-input-json.

    Now, let us chage the memory and timeout of AWS Lambda function that we have created earlier. Follow the Steps given below and observe the corresponding screenshots attached for this purpose −

    Step 1

    The memory and timeout before the change occurred is as follows −

    Step 2

    Now, with update-function-configuration, let us change the memory and timeout to 320MB and timeout to 10s. For this purpose, use the following command with values −

    aws lambda update-function-configuration --function-name “awslambdusingcli” --timeout 10 --memory-size 320 Step 3

    Then you can see the following output as the display −

    Step 4

    The display in AWS console after using update-function-configuration is as follows −

    Update-function-code

    This api will update the code for an existing AWS Lambda function.

    Commands Involved update-function-code Options Involved

    The following are the options involved with the update-function-code api −

    –function-name(string) − name of aws lambda function

    –zip-file (blob) − optional. Path of the zip file which has the code to be updated.

    –s3-bucket(string) − optional. S3 bucket name which has the zip file with code uploaded.

    –s3-key(string) − optional. AWS s3 object key name which has to be uploaded.

    –s3-object-version (string) − optional. AWS s3 object version.

    –cli-input-json (string) − optional. This will perform the operation on the api as specified in the json string provided.

    –generate-cli-skeleton (string) − optional. This will output the JSON skeleton of all details without executing the api. The output can be used as a input to –cli-input-json.

    The updated code is as shown below −

    console.log("Using aws cli"); console.log() return 'Hello from Lambda from aws cli!' };

    You can use the following command with values for this purpose −

    aws lambda update-function-code --function-name "awslambdausingcli" --zip-file "fileb://awscli.zip"

    The corresponding output is as shown here −

    The display from AWS console is as shown here −

    The corresponding log output is as shown below −

    delete-function

    The delete aws cli api will delete the function given.

    Commands Included

    The command details for the same are given here −

    delete-function Options Included

    The options included in this api are as given below −

    –function-name(string) − this will take the lambda function name or the arn of the aws lambda function.

    –qualifier (string) − This is optional. Here you can specify the version of aws lambda that needs to be deleted.

    — cli-input-json(string) − Performs service operation based on the JSON string provided. The JSON string follows the format provided by –generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values.

    –generate-cli-skeleton(string) − it prints json skeleton to standard output without sending the API request.

    You can use the following command with values for this purpose −

    aws lambda delete-function --function-name "lambdatestcli"

    Now, observe that the function will not be seen in AWS Lambda function list −

    Advertisements

    Creating And Managing Dynamodb Tables Using Aws Cli

    This article was published as a part of the Data Science Blogathon.

    Introduction

    The AWS Command Line Interface (CLI) is a centralized management tool for managing AWS services. Through CLI, users can control services manually or automate them with powerful scripts. With this one tool, it can handle multiple rvices from t command line. Us stomization for several services. This article covers how the AWS NoSQL database, DynamoDB, can be managed through AWS CLI, including creating and managing DynamoDB tables.

    Overview of

    Amazon DynamoDB is a fully managed AWS NoSQL database service best suited for high-performance queries on large datasets. It delivers consistent and fast performance for all applications without downtime or performance degradation.

    Key features: Why DynamoDB?

    Automatic partitioning and SSD-based storage.

    No need to worry about patching and updating databases.

    Supports cross-region replication, which helps to access data globally.

    Offers on-demand backup features with long-term retention and archiving.

    Use cases:

    It stores metrics from multiple data sources, like IoT Sensors, Web Applications, etc. The Time to Live (TTL) feature allows users to control data efficiently.

    It helps to store and maintain Analytical Data, Player Data, Leaderboards, and Player Session Records with ease while providing better performance.

    Steps for the Creation and Management of DynamoDB Tables using AWS CLI

    To create and manage tables in DynamoDB, users have to follow the following steps:

    1. AWS CLI Installation

    2. Configure and Set CLI credentials

    3. Creation of tables in the CLI using the c ble command

    4. Management of Tables and Attributes

    Step 1: AWS CLI Installation

    AWS CLI can be installed on Windows, macOS, or Linux operating systems. Amazon Linux AMI does not need manual installati  it already includes AWS CLI in its OS distribution.

    Linux OS :

    Use the following commands to install the latest version of AWS CLI on Linux x86 (64-bit).

    unzip awscliv2.zip sudo ./aws/install

    macOS:

    First, Install Homebrew on macOS, and then use the following commands to install the latest version of AWS CLI.

    brew install awscli

    To verify credentials, the user can use the following command:

    aws sts get-caller-identity

    Windows:

    The latest Windows installation package can be downloaded and installed from the following website:

    Another way to install CLI is by running the following command:

    To confirm CLI installation, the user can run the following command:

    aws --version Step 2: Configure and Set CLI credentials

    After installation, configure it with your credentials through the following command:

    aws configure

    This command asks you to enter details, including the Access Key, Secret Key, Region, etc.

    Step 3: Creation of tables in the CLI using the create-table command

    To create a table in DynamoDB, use the create-table command with four arguments:

    –table-name – It denotes the table name to be created by the user.

    –attribute-definitions – Denotes a list of attributes and their types that the user will use in the table and indexes.

    –key-schema – Denotes the attributes that make up the Primary Key for the table or an index.

    –billing-mode – Controls how users are charged for read and write throughput, and its value can be either PROVISIONED or PAY_PER_REQUEST.

    Let’s create a table with the following details:

    Table Name: Employee_Data

    AttributeNames: Emp_Id, Name, Salary, Department, Position

    Range Key: Department

    Partition Key: Emp_Id

    Billing Mode: PAY_PER_REQUEST

    CLI command to create a table based on the above details will be:

    aws dynamodb create-table --table-name Employee_Data --attribute-definitions AttributeName=Emp_Id,AttributeType=S AttributeName=Name,AttributeType=S AttributeName=Salary,AttributeType=N AttributeName=Department,AttributeType=S AttributeName=Position,AttributeType=S --key-schema AttributeName=Emp_Id,KeyType=HASH AttributeName=Department,KeyType=RANGE --billing-mode PAY_PER_REQUEST Step 4: Management of and Attributes

    The tables and associated attributes can be managed through specific AWS CLI commands. Such commands, along with their functions, include the following :

    List Tables

    To list all the created DynamoDB tables using CLI, use the following command:

    aws dynamodb list-tables

    Describe Table

    To describe the DynamoDB table using CLI, use the aws dynamodb describe-table command. It returns detailed information about the table, including table key schema, provisioned WCU, RCU, table status, etc.

    aws dynamodb describe-table --table-name Employee_Data

    Delete Table

    To delete the DynamoDB table using CLI, use the aws dynamodb delete-table command given below.

    aws dynamodb delete-table --table-name Employee_Data

    Backup Table

    To backup all the DynamoDB table data on demand, use the following command:

    aws dynamodb create-backup --table-name Employee_Data --backup-name Employee_Data -backup-$(date +"%m-%d-%Y")

    Put Item

    To insert a new record to the DynamoDB table, use the following command:

    aws dynamodb put-item --table-name Employee_Data --item '{"Emp_Id": {"S": "110"}, "Name": {"S": "Teena"},"Salary": {"N": "65000"},"Department": {"S": "Sales"},"Position": {"S": "Manager"}}'

    Get Item

    To get a particular Table Item by its key or combination of keys, use the following command:

    aws dynamodb get-item --table-name Employee_Data --key '{"Emp_Id": {"S": "115"}}' --consistent-read

    Get All Items / Scan

    To run a scan operation or get all Items from the DynamoDB table using CLI, use the following command:

    aws dynamodb scan --table-name Employee_Data

    Delete Item

    Table Item deletion can be only made using its Primary Key by using the following command:

    aws dynamodb delete-item --table-name Employee_Data --key '{"Emp_Id": {"S": "111"}}' Conclusion

    Users can use the AWS Management Console or the AWS CLI to manage the AWS services. A developer prefers AWS CLI over other techniques because it provides more accurate control over other services and helps in script automation. Hence, table creation and management in DynamoDB are made easy using a particular set of CLI commands.

    Key Takeaways:

    AWS Command Line Interface (CLI) is a centralized management tool for managing AWS services.

    Amazon DynamoDB is a fully managed AWS NoSQL database service best suited for high-performance queries on large datasets.

    Creating a table is done through the aws dynamodb create-table command.

    To get general information about the table, use the aws dynamodb describe-table command.

    To insert a new record, use the aws dynamodb put-item command.

    The aws dynamodb scan command will get the entire Table Items or perform a scan operation.

    Table Items can be deleted using the aws dynamodb delete-item command.

    The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

    Related

    Difference Between Static And Dynamic Testing

    As we know that testing is the most important stage in the process of delivery of any application or software. Testing not only validates the quality of an application but also provides an opportunity to the developer to improve its product.

    Every application is being developed in some high or low level language which means some code has been written for its development so on the basis of execution of code written for the application there is classification of testing namely static testing and dynamic testing.

    In this article, we will discuss all the important differences between static testing and dynamic testing. Let’s start with some basics of static testing and dynamic testing.

    What is Static Testing?

    Static testing is the testing in which code written for application is not executed during testing phase and only review of code is performed and basis on which defects and code quality has been examined. As its name implies, static testing performs the static verification of the code. It targets the assessment of program code and documentation.

    Static testing is generally performed before the compilation of the code. Static testing involves two types of testing techniques namely review and static analysis.

    What is Dynamic Testing?

    Dynamic testing there is execution of code written for the application and then defects and application behavior has been examined. Dynamic testing is performed to examine the behavior of the software based on dynamic inputs. The dynamic testing of a software product is performed after compilation of the software code.

    Dynamic testing is classified into two types namely – white box testing and black testing. In software testing techniques, the dynamic testing is one of the essential tools for detecting any security threats. The dynamic testing increases quality of the product.

    Difference between Static and Dynamic Testing

    The following table highlights the major differences between Static Testing and Dynamic Testing −

    Parameter Static Testing Dynamic Testing

    Definition Static testing is the testing in which code written for application is not executed during testing phase and only review of code is performed and basis on which defects and code quality has been examined. Dynamic testing there is execution of code written for the application and then defects and application behavior has been examined.

    Nature of testing As name states static testing does the static verification process in which the requirement and corresponding written code has been verified. Dynamic testing does the validation process which examines the expected behavior of the application based on dynamic inputs provided to the application.

    Testing target Static testing targets to the assessment of code and documentation. Dynamic testing targets the runtime bugs/bottlenecks in the software system.

    Prerequisite For static testing, a checklist of application process and documentation is required. For dynamic testing, test cases for execution are to be developed.

    Stage of testing Static testing generally get performed before compilation of code Dynamic testing mostly performed after compilation of code.

    Cost to Company In Static testing, the cost of finding the defects and fixing them is less. Also, the Return on Investment is high because static testing is carried out at an early stage of development. In case of Dynamic testing, the cost of finding and fixing the defects is high. Also the Return on Investment (RoI) is low because this process is carried out after the development phase.

    Conclusion

    The most important difference between static and dynamic testing is that the static testing checks the defects in software without actual execution of the software code and it analyzes the static behavior of the software, while dynamic testing is used to analyze the dynamic behavior of the software.

    Aws Lambda – Function In Python

    AWS Lambda – Function in Python

    In this chapter, we will create a simple AWS Lambda function in Python and understand its working concepts following detail.

    Before proceeding to work on creating a Lambda function in AWS, we need AWS toolkit support for Python. For this purpose, follow the steps given below and observe the corresponding screenshots attached −

    Step 1

    Login to AWS console and create Lambda function and select the language as Python.

    Step 2 Step 3

    Now, save the changes and the test the code to see the output. You should see the following output and logs when you test it in AWS console using the test button from the UI.

    Step 4

    Now, you can write code inside any editor or an IDE for Python. Here, we are using visual studio code for writing the code. You should later zip the file and upload in AWS console.

    Here, we have zipped the code and using it AWS console.

    Step 5

    Now, select Upload a .ZIP file option as shown below −

    Handler Details for Python

    Note that the handler has to be name of the file followed by name of the function. In the above case, our file name is chúng tôi and name of the function is my_handler; so the handler will be hellopython.my_handler.

    Once the upload is done and changes are saved, it actually shows the details of the zip file in the online editor in AWS Lambda console. Now, let us test the code to see the output and logs.

    Now, let us understand the details of the Lambda function using the following sample code −

    def my_handler(event, context): return "aws lambda in python using zip file"

    In the above code, the function name my_handler is having 2 params, event and context.

    Context Object in Python

    Context object gives details like the name of the Lambda function, time remaining in milliseconds, request id, cloud watch group name, timeout details etc.

    The methods and attributes available on context object are shown in the tables given below −

    Sr.No Method Name & Description

    1

    get_remaining_time_in_millis()

    This method gives the remaining time in milliseconds until the lambda function terminates the function

    Sr.No Attribute & Description

    1

    function_name

    This gives aws lambda function name

    2

    function_version

    This gives the version of aws lambda function executing

    3

    invoked_function_arn

    This will gives ARN details.

    4

    memory_limit_in_mb

    This shows the memory limit added while creating lambda function

    5

    aws_request_id

    This gives the aws request id.

    6

    og_group_name

    This will give the name of the cloudwatch group name

    7

    log_stream_name

    This will give the name of the cloudwatch log stream name where the logs are written.

    8

    identity

    This will give details about amazon cognito identity provider when used with aws mobile sdk. Details given are as follows −

    identity.cognito_identity_id

    identity.cognito_identity_pool_id

    9

    client_context

    This will details of the client application when used with aws mobile sdk. The details given are as follows −

    client_context.client.installation_id

    client_context.client.app_title

    client_context.client.app_version_name

    client_context.client.app_version_code

    client_context.client.app_package_name

    client_context.custom – it has dict of custom values from the mobile client app

    client_context.env – it has dict of environment details from the AWS Mobile SDK

    Let us see a working example in Python which outputs the context details. Observe the code given below −

    def my_handler(event, context): print("Log stream name:", context.log_stream_name) print("Log group name:", context.log_group_name) print("Request ID:",context.aws_request_id) print("Mem. limits(MB):", context.memory_limit_in_mb) print("Time remaining (MS):", context.get_remaining_time_in_millis()) return "aws lambda in python using zip file"

    The corresponding output of the code shown above is given below −

    Logging using Python

    To log info using Python, we can use print or logger function available. Let us use the above example of context and check inCloudWatch to see if the logs are printed. Observe the following code −

    def my_handler(event, context): print("Log stream name:", context.log_stream_name) print("Log group name:", context.log_group_name) print("Request ID:",context.aws_request_id) print("Mem. limits(MB):", context.memory_limit_in_mb) print("Time remaining (MS):", context.get_remaining_time_in_millis()) return "aws lambda in python using zip file"

    The output of this code in CloudWatch is as shown below −

    Observe the following example to understand about using logger to print logs to CloudWatch −

    import logging logger = logging.getLogger() logger.setLevel(logging.INFO) def my_handler(event, context): logger.info('Using logger to print messages to cloudwatch logs') return "aws lambda in python using zip file"

    The output for this will be as shown in the screenshot given below −

    Error Handling in Python for Lambda function

    In this section, let us see a working example which shows how to handler errors in Python. Observe the piece of code given here −

    def error_handler(event, context): raise Exception('Error Occured!')

    The log display is as shown in the image here −

    Advertisements

    What Is Kubernetes On Aws?

    Google Labs created Kubernetes, a container management platform, to manage containerized applications in many settings, including physical, virtual, and cloud infrastructure. It is open-source technology that aids in developing and controlling application containerization. Kubernetes can automate the distribution, scaling, and management of application containers across clusters. It can build infrastructure that is centered around containers. Running applications on clusters of physical and virtual machine infrastructure is one of Kubernetes’ core features. It is also capable of running apps on the cloud. It aids in the transition to infrastructure focused on containers rather than hosts.

    Kubernetes enables you to create sophisticated containerized apps and operate them efficiently over a server cluster.

    Kubernetes provides portability and quick, easy deployment. Businesses may expand without redesigning their infrastructure by utilizing various cloud service providers if necessary.

    Kubernetes handles high availability both at the application and infrastructure levels; when properly configured, Kubernetes aids in keeping your applications up and running even if one Kubernetes node is offline.

    How Kubernetes Works

    According to the available compute resources and the resource needs of each container, Kubernetes manages a cluster of compute instances and schedules the execution of containers on the cluster. You may operate and scale one or more containers together as a pod, a natural grouping for containers.

    The control plane software for Kubernetes determines when and where to launch your pods, controls traffic routing, and scales your pods depending on usage or other criteria you designate. According to their resource needs, Kubernetes launches pods on your cluster automatically and restarts them if they or the instances they are executing fail to deliver. Kubernetes uses the IP address and unique DNS name assigned to each pod to link your services to one another and outside traffic.

    Kubernetes installation on Amazon EC2 Machines

    An Amazon EC2 instance is virtual server that executes applications on the AWS architecture in Amazon’s Elastic Compute Cloud (EC2). Using Amazon EC2, you may deploy as many or as few virtual servers as you want, set up secure networking, and control storage. The user doesn’t need to predict traffic since Amazon EC2 lets you scale up or down to manage shifting demands or popularity spikes.

    Without utilizing Amazon’s managed container services, you must first establish the requisite Amazon EC2 instances before installing the Kubernetes distribution on AWS. Users are in charge of provisioning the VMs and installing and administering Kubernetes because Amazon offers virtual machines to host your Kubernetes nodes.

    Kubernetes with Amazon EKS

    Elastic Kubernetes Service (Amazon EKS) is a managed service that makes it simpler to operate Kubernetes on AWS. Organizations may use EKS to operate Kubernetes without setting up and maintaining a control plane or worker nodes. To put it simply, EKS makes it incredibly easy to administer and maintain highly available Kubernetes clusters on AWS.

    The two major elements of each EKS cluster are −

    Control Plane − There are three Kubernetes primary nodes in three distinct availability zones that make up the Control Plane (AZs). The network load balancer serves as the gateway for all incoming traffic to Kubernetes API (NLB). It functions on Amazon’s virtualized private cloud. The Control Panel is entirely handled by AWS and cannot be managed by the company directly.

    Worker Nodes − The Amazon EC2 instances host the Worker Nodes. As a worker node, you may utilize any AWS instance. Provisioning these worker nodes or connecting them through SSH manually is possible. The control plane oversees and keeps track of where and when containers are started, while a cluster of worker nodes maintains and executes the containers for an organization. AWS sets up, grows, and securely administers the Control Plane, while worker nodes are provided using EKS with only one command in the EKS GUI, CLI, or API.

    The AWS administration console may be used to set up a new Kubernetes cluster using EKS quickly. Following that, containerized apps may be scheduled in the new cluster in the same manner as in any other Kubernetes setup. You don’t have to install Kubernetes, administration or monitoring tools, or supply your nodes if you use EKS. To upgrade to newer versions of Kubernetes as they become available, you will still need to carry out certain manual activities.

    Conclusion

    Running Kubernetes on AWS will free up time for your company to focus solely on the core product while saving you the hassle of managing the infrastructure. It would also assist to reduce the need for additional IT staff by enabling your product to satisfy the steadily growing demand from your user base.

    Update the detailed information about Host Dynamic Website Using Aws Ec2 Instance on the Moimoishop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!