Thursday 5 July 2018

AWS Tutorial Terminology page 5

AWS Tutorial Terminology page 5

Question: What is difference between stored volumes vs cached volumes?
Volume gateway provides an iSCSI target, which enables you to create volumes and mount them as iSCSI devices from your on-premises or EC2 application servers. The volume gateway runs in either a cached or stored mode.


In the cached mode, your primary data is written to S3, while retaining your frequently accessed data locally in a cache for low-latency access.

In the stored mode, your primary data is stored locally and your entire dataset is available for low-latency access while asynchronously backed up to AWS.


Question: What is VPC flow logs?
VPC Flow Logs is a feature that enables you to capture information about the IP traffic going to and from network interfaces in your VPC.


Question: Where VPC flow logs are stored?
Flow log data is stored using Amazon CloudWatch Logs.


Question: What does do VPC flow logs?
to troubleshoot why specific traffic is not reaching an instance, which in turn helps you diagnose overly restrictive security group rules.
You can also use flow logs as a security tool to monitor the traffic that is reaching your instance.


Question: What are five pillars of AWS Well-Architected?
  1. Security
  2. Reliability
  3. Performance
  4. Cost optimization
  5. Performance Excellence



Question: What is Placement Group?
Placement Group is a logical grouping of instances within a single Availability Zone (AZ) that enables applications to participate in a low-latency, 10 Gbps network. You create a placement group first, and then you can launch instances in the placement group.

Question: What is CNAME record?
CNAME record is a type of DNS record that maps an alias name. CNAME records are typically used to map a subdomain such as www or mail to the domain hosting that subdomain's content.


Question: What is Alias record?
An ALIAS record is a virtual record that we create to provide CNAME-like behavior on apex domains.
For example, if your domain is example.com and you want it to point to a myapp.herokuapp.com, then you cannot use a CNAME record, but you can use an ALIAS record.


Question: What is difference between CNAME Records and Alias Records?
Route 53 charges for CNAME queries whereas does not charge for Alias Records.


Question: What is difference between aws Scale up vs scale out?
Scaling up: when you change the instance types within your Auto Scaling Group to a higher type (for example, changing an instance from a m4.large to a m4.xlarge), scaling down is to do the reverse.
Scaling out: is when you add more instances to your Auto Scaling Group and scaling in is when you reduce the number of instances in your Auto Scaling Group.


Question: What is Amazon Kinesis Data Streams?
Amazon Kinesis Data Streams enables you to build custom applications that process or analyze streaming data for specialized needs.


Question: What is AWS Direct Connect?
AWS Direct Connect makes it easy to establish a dedicated network connection from your premises to AWS.


Thursday 14 June 2018

Get the access token with OAuth 2.0 for Google API


Follow Below 4 steps to get the access token with OAuth 2.0 for Google API


1. Obtain OAuth 2.0 credentials ("Client ID" and "Secret Key") from the Google Developers Console.
  • Go to https://console.developers.google.com/
  • Select your project (create new project, If not have created before).
  • Click on "APIs & auth"
  • Click to "APIs", Now you have all the list of Google APIs  .
  • Select OR Search the APIs from search box, the one which you want to use.
  • Select API and Click on "Enable API". (I enable "Google Webmaster Tools API")
  • Now, click on "Credentials", Click on "Create new Client ID" under OAuth tab.
  • Popup will come. click on "Configure consent screen".
  • New form will appear. Fill the details and click on "Save".
  • Confirmation page appear, Click on "Create Client ID"
  • Now you will see the screen simpilar to below:

 Obtain OAuth 2.0 credentials
 Obtain OAuth 2.0 credentials
  • m. Get the "client Id" and "Client secret". (DON'T SHARE IT).


2. Create a new page in PHP like http://www.domain.com/auth-url.php
Add this URL in "Authorized redirect URIs" in your project (in Edit setting) above created.


3. Get the GET Access token from google using "Client ID" and "Secret Key"
Add the below code in "auth-url.php"
  define(YOUR_CLIENT_ID,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
  define(YOUR_CLIENT_SECRET,'xxxxxxxxxxxxxxx');
if (isset($_GET['code'])) {    
    $code = $_GET['code'];
    //Set the Auth URL
    $url = 'https://accounts.google.com/o/oauth2/token';
    
    //Set the Auth Parameter
    $redirectUri='http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
    $params = array(
        "client_id" => YOUR_CLIENT_ID,
        "client_secret" => YOUR_CLIENT_SECRET,
        "redirect_uri" => $redirectUri,
        "grant_type" => "authorization_code",
        "code" => $code,
    );

    /** Init the curl */
    $ch = curl_init();
    curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
    curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
    curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    if ($info['http_code'] === 200) {
        header('Content-Type: ' . $info['content_type']);
        return $output;
    } else {
        die('An error occured');
    }
    /** Init the curl */
    
} else {

    $url = "https://accounts.google.com/o/oauth2/auth";

    //Set the Auth Parameter
    $params = array(
        "response_type" => "code",
        "client_id" => YOUR_CLIENT_ID,
        "redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],        
        "scope" => "https://www.googleapis.com/auth/webmasters.readonly" //I have added scope for webmaster tool
        
    );

    $requestTo = $url . '?' . http_build_query($params);

    //Redirect the page
    header("Location: " . $requestTo);
} 



4. You will get result simpliar to below.
{ "access_token" : "ya29.kgGOtdWEj32NOSxLWkZXAaXAagmkP-4WgHEd8gpUfuelHD_lslquKzHMVV2OnnNc5h1BKWkY8aeCrA", "token_type" : "Bearer", "expires_in" : 3600 }

Here you got access_token, token_type and expires_in (in Seconds).


If this code does not work and need any assistance, Please feel free to comment.