AWS in 5 minutes

This post will give you a basic understanding of what Amazon Web Service is, how components in it works, what each component is responsible for at a very high level – all these in just 5 minutes.

This post is gives you a brief idea about the components used in aws. This will surely help you understand things when aws developers are discussing about topics and issues while at work.

EC2Elastic Cloud Computing instance is where you run your web app server or a micro-service server. This is one of the primary component of AWS. You can create multiple instances of the servers in multiple availability zone so that if one zone goes down your services to end users are not affected. Session maintainence can be configured here or in ELB

ELBElastic load balanacer automatically distributes incoming application traffic across multiple targets. It handles the traffic coming from the public networks (users/mobile/consumers). The major functionality of this component is route the traffic to different servers balancing the load from incoming traffic. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones.

ELB facing the public network will be inside a public subnet to make it accessible. Apart from this and S3 instance all other components will be inaccessible to public as they will be configured with private subnet. This would be the best place to have session stickiness.

S3Simple Storage Service is used for storing all static files like documents, audio, video, image files. This service is only used for storing and retrieving the files. Glacier is used in connection to S3 to archive the least used or unused files to reduce the storage space.

AWS
The diagram represents typical web app architecture using some of the important components of amazon web services. Also shows the interactions between the components.

DataBases:

RDSRelational DataBase is the place where you store and manage your application data. This service supports RDBMS solutions like MySQL, etc. This service also supports the Master-Slave architectures.

NoSQL DB are used if web app solution needs a document based databases like DynamoDB, etc.

Security Group – is used to manage the access to service anyone can have. Each service must ideally have a security group defined.

Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. It is designed to give developers and businesses a way to route end users to your application servers.

IAMIdentity and Access Management is the one where you can add/update/delete users and their permissions. Generally there will be end users, administrators, developers.

Elastic Cache is a managed, in-memory data store services. You can choose Redis or Memcached to power real-time applications. ElastiCache is a popular choice for Gaming, Ad-Tech, Financial Services, Healthcare, and IoT apps.

For administrators: CloudWatch monitoring service for AWS cloud resources and the applications you run on AWS. It keeps an eye your whole setup and triggers a notification using SNS service to email the administrators if there arises any warning or alert on servers using SES service.

Lambda services are generally used for solutions designed with serverless architectures.

Hope this would be useful to in one or the other way, at least giving you a sneak peak about what AWS is all about.

Advertisements

Obj-C — Swift — Obj-C

This is one of the rare scenarios one might get into, but the problem and its solution are unique and the simplest one here.

  • Have you come across a scenario where you felt the need for an additional method in a class inside a framework (one of the Pods you added) to achieve your work?
  • Is the library implemented in Objective-C?
  • Is your legacy code in Objective-C and now you are strategically moving to Swift?

Today at work my friend, Vinodh, asked me this:

“I have a pod framework which is in Objective-C, I need to add a functionality but needs to be used in Obj-C for now and may be used in Swift file in future. What is the best way to do this?

Let us say we have a class called Person inside one of your pod frameworks. This Person class has name, age and gender as properties, with a function to format the name.

// Objective-C header file of Person class
#import 

typedef enum : NSUInteger {
    male,
    female
} Gender;

@interface Person : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) Gender *gender;
@property (nonatomic, strong) NSUInteger *age;

- (NSString*)formattedName;

@end

// Objective-C Implementation of Person class
@implementation Person

- (NSString*)formattedName
{
    return [NSString stringWithFormat:"This is %@",self.name];
}

@end

When the formattedTitle method is called on a person object with value for name property ‘Vinodh’ it would print like “This is Vinodh”.

Now we need to extend this Person class with another method say a new format which tells the age along with the name.

In classic Objective-C style it would be adding a category to Person class, Importing this category wherever you need this new method. This would have been the best way before Swift was introduced.

But there is a disadvantage if new developer join unitl and unless (s)he imports the category header, code completion will not show the new method. Probably the new developer will end up writing the same method creating a new category again. This is a problem.

Swift to rescue. Do the following:

  • Create a Person class extension and write the needed method
  • Now create a protocol and declare the method signature
  • Now prefix the protocol with @objc to make this available in Obj-C files

Here’s how you do it.

@objc protocol Formats {
    func getFormattedName(with ageHidden: Boolean) -> String
}

extension Person: Formats {
    func formattedName(with ageHidden: Boolean) -> String {
        let formattedString: String = ageHidden ? "This is \(self.name)" : "This is \(self.name) aged \(self.age) years."
        return formattedString
    }
}

Now wherever you type [personObject form… in Obj-C or in personObject.form… in Swift the code complete will show you both the methods one Person class another from the extension we added.

Love to hear more stories from your side. Please do share in comments.

Happy Coding!

WordPress on local machine

When I talked to a friend about learning wordpress development he said why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

It’s a true, a reality. With node, MEAN stack, Swift for server side and similar other frameworks a developer can build and run his own site with latest technology. WordPress still works on php, MySQL – the classic xAMP stack.

Why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

This doesnt mean we should stop learning old technology which are still doing good. Those are the systems which are still doing good, scaling good. They are thought through and are designed in a better way to last long compared to any new platforms today. I mean Facebook is still powered by php.

This doesn’t mean new technology is not there in terms of scalability. Sad truth is most never get opportunity to scale. Some never see the light of the day and some which get to see hardly have any subscribers and developers of that blog never scale them.

Why am I learning this now?

Learn and understand, experiment, know inside of it and whereabouts of what needs to be done then customize it according to your needs.

  • WP gives a base to start creating your own websites primarily blogs.
  • Lot of templates available or build your own and share.
  • Spend time in customizing as per your needs rather than build from scratch.
  • We can learn how various components are used.
  • Architectures and patterns followed.
  • The schema design.
  • Its always interesting to learn old technologies.

This is the reason why I went ahead with starting on wordpress. As a first step I wanted to install wordpress and try some themes and plugins. But to install I need a server to host and need a database hosting too. Next I searched for how to install WordPress locally on my system? got the results.

It needs a xAMP stack – Apache-MySQL-PHP either on Linux, macOS or Windows. I have a macOS. Now next come how to start a Apache server? After some searching on internet Found MAMP which makes your task very easy. MAMP is for macOS and Windows too and there is another one WAMP for windows only.

There is no better way to have a server of your own for free and do your experiments. And the only best way for this full freedom installing it locally on your system.

Install WordPress locally:

  • Download MAMP
  • Install MAMP or WAMP as per their site
  • Download WordPress Remember this is wordpress.org not .com
  • Unzip the downloaded wordpress file, you must get a folder – wordpress
  • Copy the wordpress folder into installed MAMP folder’s htdocs folder*
  • Now click on Start servers
  • Once the loading spinners stop and you see green in front of Apache and MySQL your servers are running
  • Open your favorite browser and type http://localhost:8888 and hit enter
  • Set up database –
    • Go to localhost/phpmyadmin
    • Go to Databases, add a name for the table and click Create
  • Configure WordPress –
    • Now open a browser tab and type localhost:8888/wp-admin
    • Follow the wizard
    • When asked for enter Database name, username, password, Host
    • By default username and password both are ‘root
    • Leave the Table prefix as it is and click Submit
    • Next click on Run Installation
    • Give a name, username-password and email-id for your blog
    • Click on Install wordpress. Success!
    • Now when you login, you should be able to see Admin console
Congrats!! You are up and running 
wordpress instance locally

*Alternatively you can also set the path from which MAMP has to serve. Launch MAMP – Go to Preferences – Web Server tab – Change the Document Root folder.

Where to go from here?

I am yet to do this, but definitely next step is to design your website and customize your wordpress installation. Here is a 7 video series on how to build a wordpress site

Now explore installing themes, creating a couple of themes and plugins. Along with creating them it will be interesting to understand how everything fits. I have just installed WP on my system and yet to explore all these.

This is where I learnt how to install WordPress locally.