Friday, February 17, 2017

Custom Authorization HTTP Request in AWS NodeJS Lambda function

Below is the sample code for AWS NodeJS lambda function. This will show how to make an HTTP request with Custom Authorization using "request" node module.
request v2.79.0 - Simplified HTTP request client.
Request package is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

/// Module to test HTTP POST Request
/// Created By: Sohan Fegade
/// Created Date: 17-Feb-2017

var request = require('request');
var buffer = require('buffer');

console.log('Loading http-test-module');

exports.handler = function (event, context, callback) {

    if (event != null) {
        console.log('event = ' + JSON.stringify(event));

        var username = 'sampleuser';
        var password = 'samplepassword';
       
        var auth = 'Basic ' + buffer.Buffer(username + ':' + password).toString('base64');
       
        var options = {
            url: 'https://www.sample-auth-url.com/oauth/token',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': auth
            },
            json: {
                'type': 'test',
                'input': 'test',
                'field': 'test',
                'scope': 'urn:scope-api',
                'token-type': 'auth-token'
            }
        }

        request.post(options, function (error, response, body) {
            if (!error && response.statusCode === 200) {
               console.log('Access Token : ' + body.access-token);
            }
               
            context.callbackWaitsForEmptyEventLoop = false;
            callback(null, 'SUCCESS');
       });
    }
    else {
        console.log('No event object');
    }
};
 

Tuesday, January 31, 2017

AWS Route 53

Amazon Route 53 (Route 53) is part of Amazon.com's cloud computing platform, Amazon Web Services (AWS). Route 53 provides a scalable and highly available Domain Name System (DNS). The name is a reference to TCP or UDP port 53, where DNS server requests are addressed. In addition to being able to route users to various AWS services, including EC2 instances, Route 53 also enables AWS customers to route users to non-AWS infrastructure. Route 53's servers are distributed throughout the world. Amazon Route 53 supports full, end-to-end DNS resolution over IPv6. Recursive DNS resolvers on IPv6 networks can use either IPv4 or IPv6 transport to send DNS queries to Amazon Route 53.
One of the key features of Route 53 is programmatic access to the service that allows customers to modify DNS records via web service calls. Combined with other features in AWS, this allows a developer to programmatically bring up a machine and point to components that have been created via other service calls such as those to create new S3 buckets or EC2 instances.
AWS supposedly named the service Route 53 because all DNS requests are handled through port 53, and the "route" piece resembles the historic "Route 66" of the USA. And Route is basically for routing any traffic to Amazon DNS.

Monday, January 30, 2017

Developer Guide for AWS Lambda using Node.JS

Developing Simple Lambda function using Node.js

Pre Requisite:
• AWS Account
• Visual Studio
• Node.JS tool

Step 1: Create Lambda function in Visual Studio
Step 1.1 Open Visual Studio (Run as Administrator)
Add Lambda Project in Visual Studio
File -> Add New Project
Create new project as “Hello World”.
On Next screen select – Create Simple project
Click Finish.
Below screen will appear after click on Finish.
By default some files will be added in project which we can be found in Solution explorer.
  1. _testdriver.js  : This is a utility file to help invoke and debug the lambda function. It is not included as part of the bundle upload to Lambda.
  2. _sampleEvent : This is JSON file use to set Event sample event data to test / debug
  3. App.js : Main program file in which we will write code (Application logic)
  4. npm : Node Package module. Utility to install NPM package
  5. node_modules : Repository for node.js packages. Folder contains supporting node module files. By default it contains “aws-sdk” module. When add new module it will automatically get updated and store supporting file
Open App.JS file, file contains below code:
exports.handler : start execution of your Lambda function

Step 1.2 – Update _sampleEvent.json file
Step 1.3 – Update app.js file with below code
Step 1.4 – Run Application (Press F5), below screen should appear which contains Event information from _sampleEvent.JSON file
This complete our Hello world program.

Step 2: Deploy Lambda function in AWS console
Step 2.1: Open AWS console and find Lambda under Compute service.

Step 2.2: Screen will show List of Lambda functions. Click on Create Lambda function button
Step 2.3: Screen will show list of Blueprint use to create Lambda function. We can select existing blueprint or Skip this part and move next.
Click on Skip button on screen (Bottom right corner)
Step 2.4: Configure Lambda function.
Configure function - Set Name,Description,Runtime.
Set Lambda Function code details as shown below
Code entry type: Upload ZIP file
Handler: Main JavaScript file, in our case it is app.js. Update Handler Textbox as app.handler.
Role: Set role as lambda_basic_execution

Step 2.5: Create Zip folder contains code and Node modules
To create ZIP file open Physical location of Lambda code (HelloWorld Lambda Developed in VS2013)
Select below files/folder for ZIP,
1.    Node_modules
2.    App.js
Step 2.6:  Set Advanced settings.
Review Lambda function
Click on Create Function button. This will create your First Lambda Function.

Step 3: Configure Test Event and Test Lambda function
Step 3.1:  To set Test event click on Action button and select “Configure test event” option.

Select event template and set data. This is same data which we used to test in debug mode. You can find this in _sampleEvent.json file. Click Save button (Bottom Right corner)
Click on Test button to test Lambda function. Scroll down and you will see below content on screen.
Highlighted section in Blue is output generated by Context object.
Section highlighted in yellow is output log.

Step 4: See Test result logs in CloudWatch
Step 4.1: To check logs in click on Monitor Tab. Click “View logs in CloudWatch”
You can see details logs on new screen.

Tuesday, January 10, 2017

C++ 17: A Newer Version of C++ to bring more power and simplicity

There is no programmer in the world who don’t know about C++ programming language. The updated version of C language with object orientation. C++ was introduced 33 years ago by Bjarne Stroustrup. As long as you keep it simple C++ is a good and reasonably modern object-oriented language that is still close enough to the machine architecture to produce programs that run about as fast as possible.
The new C++ 17 standards are introducing new features like structured bindings and if initialisers, making this vintage programming language “feature complete”. The C++ community is calling C++17 the start of a new era that will bring powerful technical specifications and overcome the known issues.
List of the most features that will be on C++ 17:
  • C++17 is based on C11
  • Dynamic memory allocation for over-aligned data
  • Guaranteed copy elision
  • Forward process guarantees (FPG)
  • Structured bindings
  • if (init; condition) and switch (init; condition)
  • constexpr if
  • Inline variables
  • A weaker version of fixed order-of-evaluation for expressions
  • Template argument deduction for class templates
According to the c++ community, this major update aims to make C++ an easier language to work with and brings powerful technical specifications.

Sunday, January 1, 2017

New Year Greetings 2017


Your success and happiness lies in you.
Resolve to keep happy, and your joy and you shall form an invincible host against difficulties.

Thursday, December 22, 2016

C# 7: New Features

C# is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. C# 7.0 adds a number of new features and brings a focus on data consumption, code simplification and performance. Perhaps the biggest features are tuples, which make it easy to have multiple results, and pattern matching which simplifies code that is conditional on the shape of data.
Feature List in C# 7.0
  • Local functions – code available currently in github
  • Tuple Types and literals
  • Record Types
  • Pattern matching
  • Non Nullable reference types
  • Immutable types
  • Binary Literals
  • Digit Separators
  • Type switch
  • Out var
  • Arbitrary async returns

Monday, December 19, 2016

Visual Studio 2017 Features

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft.
Codename: Dev15
Version number: 15.0
Version of cl.exe: 19.10
Supported .NET Framework versions: 2.0 – 4.6.2; Core 1.0
Below is the list of features in Visual Studio 2017:
  • New Installation Experience:
  • Visual Studio IDE:
    • Improved Code Navigation
    • Connecting to Services Using Connected Services
    • EditorConfig Support
    • New Extensibility Format
    • Modify Extensions in Bulk
    • Ngen Support
    • Roaming Extension Manager
    • Sign in and Identity Improvements
    • Lightweight Solution Load
  • Debugging and Diagnostics:
    • Attach to Process Filter
    • Reattach to Process
    • The New Exception Helper
    • Add Conditions to Exception Settings
    • Debugger Accessibility Improvements
    • IntelliTrace Events for .NET Core
    • Diagnostic Tools Window Updates
    • Performance Profiler Updates
    • CPU Usage Tool Updates
    • Chrome Debugging Support
  • Team Explorer:
    • Connect to VSTS
    • Work Item Forms
  • C# and Visual Basic:
    • IDE Experience and Productivity
    • Language Extensions and Analyzers
  • JavaScript and TypeScript:
    • TypeScript 2.1
    • JavaScript Language Service