In this post, I'm sharing questions answers on AWS services which are asked now a days.
Question 1:
How are EC2 and RDS used in production?
Answer:
For deploying java application on AWS EC2, we should have the following:
- An account on Amazon Web Services, so that we can login to console and do some settings and some changes.
- Then we need to have a terminal with SSH support, so that we can connect to amazon EC2 instance.
- Then we need to have the PEM file generated from the AWS which is a security file for the amazon EC2 instance to which we want to connect.By going to amazon web console, we can generate PEM file and can use it to connect to amazon EC2 instance.
- We need to have the IP address of EC2 instance, so that we can connect to it.
Now, we need to execute below given command to connect to our EC2 instance remotely:
ssh ec2-user@ip-address -i PEMfile
Now, we are connected to our EC2 instance. Now we check whether we have JDK installed on it or not.
We can run java -version and we can check whether java is installed or not.
Now just copy the command to install JDK from Oracle website and paste it into terminal. It will download the JDK into EC2 instance.
Now, we need to run the JDK install command. So, it will install Java on EC2 instance.
Now, we need to clone our project from github to EC2 instance.
Now, make a directory called workspace in home directory of EC2 instance and then run git clone <path> command and the project will be cloned in workspace folder.
Now, we need to expose port 5000 , so that anybody can connect to our java application.
For that we need to go to AWS console and Network and Security -> Security Groups , we need to create a new security group with port 5000.
And, now we can run our application using ip address/port/our Rest endpoint.
RDS: Relational Database Service:
For using RDS in AWS, we need to create separate Security group for configuring it by going to amazon console as discussed in previous question.
Now, we need to create an instance of RDS by clicking on Instances tag on left panel on AWS console.
Now search for RDS in search bar and it will open Amazon RDS window.
Click on instances tab on left panel.
It will ask you to create DB instance: Amazon Aurora, MySQL, SQL Server, MariaDB, PostgreSQL, Oracle etc.
Now lets select MySQL, then it asks for Choose use cases: Production, Dev/Test etc.
Select Dev/Test for example.
Now under settings: mention db instance name.
Now "Specify DB Details" screens appears. We can select MySQL version here.
We can also select for creating replica on different zones.
Also allocate storage e.g. 20 GB.
Now, provide master username and password.
Also, set the accessibility of the database: public or local. Now, it will launch RDS instance.
So it may take few minutes to create DB instance.
When we click our newly created db instance, we can see that we have a endpoint and port created.
So just open MySQL workbench and in "setup new connection" window, pass endpoint created above in Hostname field. Port will be default or use as got in above section.
Now, just pass username and password and click on Test Connection.
Now, we are connected to our new database that we just created above.
For any VPS security, we can add Inbound rules under Security groups.
Now, we have a connection entry created in Workbench. Click on it and it shows MySQL workbench default view, where we can type commands and interact.
Now, we can create database and tables as we do in MySQL.
Question 2:
How to configure and use AWS storage S3?
Answer:
AWS S3 is the storage service of the internet, where we can store and retrieve any amount of data, at any time, from anywhere on the web.
S3 is durable, flexible, cost efficient, scalable, available and highly secure.
For using AWS storage S3, we first need to configure it.
So, steps to configure S3 is:
- Open AWS Console. Login into it. Go to Services->Storage-> S3
- Now we need to create a bucket and provide bucket name, region etc. Also need to mention public permissions. Now , clicking on create bucket button, it creates a S3 bucket.
- Now , we can create folders and upload files in this bucket.
- For every uploaded file, S3 provides a URL as well to access it.
Amazon S3 is used to store the types of data which are not required on daily basis. e.g. It can be used to store any kind of certificates which are not used daily.
e.g. A hospital can use S3 to store birth certificates.
S3 works on the concepts of buckets and objects.
Bucket is like a container and object can be any file.
S3 is free for 1 year with some limitations from amazon.
Question 3:
What do you know about AWS Lambda?
Answer:
AWS Lambda allows us to run the code without doing any provisioning or managing any server.
We just need to write source code and upload it to Lambda and it will run it. That means, we don't need to manage any server.
Lambda handles scaling of our application automatically in response to each trigger our application receives.
We only have to pay for the amount of time for which our code is running.
AWS Lambda is one of the services that falls under the compute domain of services that AWS provides.
Use case of Lambda:
Whenever we are getting some videos or images which are in raw format and we need these files in thumbnails format, then for every file upload in S3, it will trigger AWS Lambda and lambda will format that raw file into a thumbnail that can be used by any client.
How does Lambda work?
When a lambda function gets a request, it sends it to one container. But when the number of requests increases, in creates more containers and balances the load.
When number of requests decreases, lambda will reduce the containers that helps in saving costs.
Even we only need to pay for the amount of time these containers are running.
AWS lambda also handles the backing up of the data.
We need to create two S3 buckets , on one we will upload the data and another bucket will be used for backing up the data. And we also need to specify one IAM rule to provide communication between these two buckets. And we require lambda function to copy the data from source bucket to destination bucket.
The lambda function is triggered everytime there is a change in the metadata of the bucket.
Thanks for reading!!
No comments:
Post a Comment