Amazon Stuff

by Admin 11. April 2017 06:56

 

Cloud Formation
Allows to create scripts to deploy infrastructure

The default scripting language for CloudFormation is JSON
Cloud Formation itself is free, however the resources it provisions will be charged at the usual rates.


What happens if Cloud Formation encounters an error by default?
It will terminate and rollback all resources created on failure.

You are creating a virtual data centre using cloud formation and you need to output the DNS name of your load balancer. What command would you use to achieve this?
FN::GetAtt

What language are cloud formation templates written in?
JSON

 

SQS (Simple Queue Service)

Messages can be 256kb of data

Amazon SQS ensures delivery of each message at least once, and supports multiple readers and writers interacting with the same queue.

A single queue can be used simultaneously by many distributed application components, with no need for thoese components to coordinate with each other to share the queue.

SQS asynchronously pulls the task messages from the queue and cannot guarantee first in first out from the queue. If the system requires that the order be preserved, you can place sequencing information in each message, so that you can reorder the messages when the queue returns them.

image pooling and retrieve steps

Asynchronously pulls the task messages from the queue

Retrieves the named file

Processes the conversation

Writes the image back to Amazon S3

Writes a "Task Complete" message to another queue

 Deletes the original task message

Checks for more messages in the worker queue

 SQS
SQS was the first service on the AWS platform
Does not offer FIFO
12 hrs visibility timeout
default visibility time out setting by default is 30 seconds.
Can extend / change by using the ChangeMessageVisibility action to specify a new timeout value
256kb  SQS message size now availble
Maximum Long Poll Time Out = 20 Seconds


Autoscalling application servers
SQS Messages can be delivered multiple times and in any order.

You are designing a new application which involves processing payments and delivering promotional emails to customers. You plan to use SQS to help facilitate this. You need to ensure that the payment process takes priority over the creation and delivery of emails. What is the best way to achieve this.

Use 2 SQS queues for the platform. Have the EC2 fleet poll the payment SQS queue first. If this queue is empty, then poll the promotional emails queue.

Your EC2 instances download jobs from the SQS queue, however they are taking too long to process them. What API call can you use to extend the length of time to process the jobs?
ChangeMessageVisibility

You have a fleet of EC2 instances that are constantly polling empty SQS queues which is burning CPU compute cycles and costing your company money. What should you do?
Enable SQS Long Polling

What amazon service can you use in conjunction with SQS to "fan out" SQS messages to multiple queues.
SNS

 

SNS (Simple Notification Service)
SNS is Push based notification service
> Topics
> Subscriptions

Protocols > HTTP, HTTPS, EMAIL, EMAIL-JSON, AMAZON SQS, Application
Messages can be customized for each protocol used in SNS

You have a list of subscribers email addresses that you need to push emails out to on a periodic basis. What do you subscribe them to?
Answer: Topic

You can use SNS in conjunction with SQS to fan a single message out to multiple SQS queues.

Tags:

AWS Steps to setup Serverless & Lambda

by Admin 11. February 2017 08:04

AWS Command Line Interface

https://aws.amazon.com/cli/

AWS Toolkit for Visual Studio

https://aws.amazon.com/visualstudio/

Install NodeJS & Git Bash

install node js tools for visual studio

https://www.visualstudio.com/vs/node-js/

Install serverless globally

The commands are here https://serverless.com/

npm install serverless -g

Create an AWS Lambda function 

In Node.js

serverless create --template aws-nodejs

 In C#

 serverless create --template aws-csharp -p serverless-Sample1 -n LambdaService

Now open the project in Visual Studio

Add yaml Syntax Highlighting Pack nuget package

https://marketplace.visualstudio.com/items?itemName=MadsKristensen.MarkdownEditor

Next

Modfiy the serverless.yml file to use the respective access credentails as below

provider:

  name: aws

  runtime: dotnetcore1.0

  stage: dev

  region: ${self:custom.configuration.providerRegion}

  credentials:

accessKeyId: ${self:custom.configuration.accessKeyId}

secretAccessKey: ${self:custom.configuration.secretAccessKey}

Note:

In the above I have referred the credentials and the region from an external config.yml file.

Here are the steps to do add the external file

Create a new config.yml file

Paste the below config stuff

#configuration

 #AWS config

providerRegion: eu-west-2 (you need to set yours here)

awsAccessKey:PASTE_YOUR_ACCESS_KEY_HERE

awsSecretKey:PASTE_YOUR_SECRET_KEY_HERE

accountId:PASTE_YOUR_ACCOUNT_ID_HERE

Going back to servreless.yml file

You add / modify default settings

eg: I have added to exclude teh git stuff as part of the deployment package

# you can add packaging information here

package:

  artifact: bin/release/netcoreapp1.0/publish/deploy-package.zip

  exclude:

  - .git/**

Now right click build.ps1 file and open with powershell

Now run this command 

./build.ps1

Now the buid will be completed an places a folder in the below location and created a package.zip file to deploy

C:\VENKAT\Learning\AWS\Dev\serverless-Sample1\bin\release\netcoreapp1.0\publish

serverless-Sample1 is my application name

Now go to the gitbash "C:\VENKAT\Learning\AWS\Dev\Serverless-Sample1>" location

Now deploy the code on the serve rusing the following command

sls deploy

The above deploy happends from the default location as below

C:\VENKAT\Learning\AWS\Dev\Serverless\bin\release\netcoreapp1.0\publish

The code is successfully deployed on the server now.

Now go to the AWS Lamda 

https://eu-west-2.console.aws.amazon.com/console/home?region=eu-west-2#

Search for Lamda

You should be able to view the lambda function we created

You can test by clicking the Test button.

 

Now its time to deploy the Lambda function on to the API Gateway

Go to the API gateway location by searching

https://eu-west-2.console.aws.amazon.com/apigateway/home?region=eu-west-2#/apis

 

Here you should be able to view the function which needs to be deployed on to API gateway

Now configure Method Execution  /users/create - GET - Method Request

You can add the 3 query params key1, key2 & key3

Now add a method HTTP Status: 200

Set the Use Lambda Proxy integration to False (UnCheck)

 

Now deploy the site from the Actions dropdown.

Test the function here 

 

Now 

https://eu-west-2.console.aws.amazon.com/apigateway/home?region=eu-west-2#/apis/ayd0i0b484/resources/g21af8/methods/GET

Make sure you deploy

https://ayd0i0b484.execute-api.eu-west-2.amazonaws.com/dev/users/create?request=test

 

Deploy to live AWS account

serverless deploy

UFunction deployed!

http://api.amazon.com/users/update

 

Janisha-GBRL01483M17.pdf (566.60 kb)

Vijay-GBRL01481M17.pdf (564.19 kb)

Tags:

AWS stuff

by Admin 10. February 2017 08:06

VPC - Virtual Private Cloud

State Machine is (also knows as work flow) or a group of states

Each state could be Task, Wait, Pass, Succeed, Fail, Choice, Parallel

 

Work Flow execution is an instance of the process or the work flow

 

Serverless N-Tier Architecture on AWS

 

Opsworks to build layers for presentation, integration and DB

Cloud formation to automate environment creation and update process

 

Dynamo DB ()  or RDS (Relational Database System)

 

Lambda functions represens the Dal

DAO Data access Object function

 

AWS API Gateway

Passthrough request

Deploy 

S3 Bucket

 

Runtime : Use nodeJs

 

S3 is an object storage service on Amazon cloud

IAM policies

 

2nd Type

 

Create Lambda functions using Cloud Formation

IAM rule

AWS Identity and Access Management (IAM) is a web service that helps 

you securely control access to AWS resources for your users. 

You use IAM to control who can use your AWS resources (authentication) 

and what resources they can use and in what ways (authorization).

 

State Machine

Step functions

AWS officially launced in 2006

Re-Invent Conference

Cloud Watch 

EC2 Elastic Compute Cloud 

 

 QR Code

 JSon is mostly Key Value pairs

 

 

 IAM 

 Accesskey id and secret key id is used only to use programatically interactiing with AWS

 username and password are only used when logging into the AWS console

 

 S3

 Simple Storage Service

 S3 is used to place to store the files in the cloud

 S3 is Object based storage (like videos/ images or any files etc to store the files)

 S3 is not Block based.

 files can me from 0bytes to 5TB

 Bucket is a folder

 files are stored in buckets

 Bucket names are unique globally

 when you upload a file in to S3 it returns a 200 status code

 

Remove all


C:\TFS\AWSPrj> .\scripts\RemoveAllServices <environmentName>

 

Tags:

Common REST API Error Codes

by Admin 3. January 2017 01:03

The error codes listed in the following table may be returned by an operation on any of the storage services.

Error code

HTTP status code

User message

ConditionNotMet

Not Modified (304)

The condition specified in the conditional header(s) was not met for a read operation.

MissingRequiredHeader

Bad Request (400)

A required HTTP header was not specified.

MissingRequiredXmlNode

Bad Request (400)

A required XML node was not specified in the request body.

UnsupportedHeader

Bad Request (400)

One of the HTTP headers specified in the request is not supported.

UnsupportedXmlNode

Bad Request (400)

One of the XML nodes specified in the request body is not supported.

InvalidHeaderValue

Bad Request (400)

The value provided for one of the HTTP headers was not in the correct format.

InvalidXmlNodeValue

Bad Request (400)

The value provided for one of the XML nodes in the request body was not in the correct format.

MissingRequiredQueryParameter

Bad Request (400)

A required query parameter was not specified for this request.

UnsupportedQueryParameter

Bad Request (400)

One of the query parameters specified in the request URI is not supported.

InvalidQueryParameterValue

Bad Request (400)

An invalid value was specified for one of the query parameters in the request URI.

OutOfRangeQueryParameterValue

Bad Request (400)

A query parameter specified in the request URI is outside the permissible range.

RequestUrlFailedToParse

Bad Request (400)

The url in the request could not be parsed.

InvalidUri

Bad Request (400)

The requested URI does not represent any resource on the server.

InvalidHttpVerb

Bad Request (400)

The HTTP verb specified was not recognized by the server.

EmptyMetadataKey

Bad Request (400)

The key for one of the metadata key-value pairs is empty.

InvalidXmlDocument

Bad Request (400)

The specified XML is not syntactically valid.

Md5Mismatch

Bad Request (400)

The MD5 value specified in the request did not match the MD5 value calculated by the server.

InvalidMd5

Bad Request (400)

The MD5 value specified in the request is invalid. The MD5 value must be 128 bits and Base64-encoded.

OutOfRangeInput

Bad Request (400)

One of the request inputs is out of range.

InvalidAuthenticationInfo

Bad Request (400)

The authentication information was not provided in the correct format. Verify the value of Authorization header.

InvalidInput

Bad Request (400)

One of the request inputs is not valid.

InvalidMetadata

Bad Request (400)

The specified metadata is invalid. It includes characters that are not permitted.

InvalidResourceName

Bad Request (400)

The specifed resource name contains invalid characters.

MetadataTooLarge

Bad Request (400)

The size of the specified metadata exceeds the maximum size permitted.

ConditionHeadersNotSupported

BadRequest (400)

Condition headers are not supported.

MultipleConditionHeadersNotSupported

Bad Request (400)

Multiple condition headers are not supported.

AuthenticationFailed

Forbidden (403)

Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.

InsufficientAccountPermissions

Forbidden (403)

Read operations are currently disabled.

InsufficientAccountPermissions

Forbidden (403)

Write operations are not allowed.

ResourceNotFound

Not Found (404)

The specified resource does not exist.

AccountIsDisabled

Forbidden (403)

The specified account is disabled.

InsufficientAccountPermissions

Forbidden (403)

The account being accessed does not have sufficient permissions to execute this operation.

UnsupportedHttpVerb

Method Not Allowed (405)

The resource doesn't support the specified HTTP verb.

AccountAlreadyExists

Conflict (409)

The specified account already exists.

AccountBeingCreated

Conflict (409)

The specified account is in the process of being created.

ResourceAlreadyExists

Conflict (409)

The specified resource already exists.

ResourceTypeMismatch

Conflict (409)

The specified resource type does not match the type of the existing resource.

MissingContentLengthHeader

Length Required (411)

The Content-Length header was not specified.

ConditionNotMet

Precondition Failed (412)

The condition specified in the conditional header(s) was not met for a write operation.

RequestBodyTooLarge

Request Entity Too Large (413)

The size of the request body exceeds the maximum size permitted.

InvalidRange

Requested Range Not Satisfiable (416)

The range specified is invalid for the current size of the resource.

InternalError

Internal Server Error (500)

The server encountered an internal error. Please retry the request.

OperationTimedOut

Internal Server Error (500)

The operation could not be completed within the permitted time.

ServerBusy

Service Unavailable (503)

The server is currently unable to receive requests. Please retry your request.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/common-rest-api-error-codes

Tags:

Angular CLI shortcuts

by Admin 16. September 2016 03:06

 

Angular CLI shortcuts
To install Angular CLI, run: $ npm install -g angular-cli

Generate a my-sample application: $ ng new my-sample


# Generate a new component
$ ng generate component my-new-component

# Generate a new directive
$ ng generate directive my-new-directive

# Generate a new pipe
$ ng generate pipe my-new-pipe

# Generate a new service
$ ng generate service my-new-service

# Generate a new class
$ ng generate class my-new-class

# Generate a new interface
$ ng generate interface my-new-interface

# Generate a new enum
$ ng generate enum my-new-enum

Tags:

Angular2 stuff

by Admin 6. September 2016 07:23

 

The * before the ngFor denotes the fact that *ngFor is what is called a structural directive, a directive that is going to affect the DOM in some way adding or removing elements to it.

 

Backtick (`) are used to define the new ES6 template strings. They are a new great feature of ES6 that let’s you write multiline strings natively and insert any expression directly within a string with a very straightforward syntax.

 

Why don’t we use the Injectable decorator in components? 

Well that’s because the Component decorator enables dependency injection directly.

 

Angular 2 has support for these data-bindings:

1. Interpolation: One-way data binding from the component to the template. Let’s you display information from the component into the template. Example: {{user.name}}.

2. Property bindings: One-way data binding from the component to the template. Let’s you bind data from the component into the template. Example: [src]="user.imageUrl".

3. Event bindings: One-way data binding from the template to the component. Let’s you bind template events to the component. Example [click)="selectuser(user)".

4. [(ngModel)]: Two-way data binding from the component to the template and vice versa. Example [(ngModel)]="user.name".

Tags:

VS 2015 Error Install-Package : Unable to load the service index for source https://api.nuget.org/v3/index.json

by Admin 8. May 2016 07:56

Visual Studio 2015 Error Install-Package : Unable to load the service index for source https://api.nuget.org/v3/index.json

Fix : 

1. Close your Visual Studio 2015

2. Navigate to %AppData%\NuGet\ folder 

3. Delete the NuGet.config file

4. Now open Visual Studio. You can notice that a new NuGet.Config file is generated

This fixes the issue

Tags:

RenderPartialViewToString / Return multiple partial views in JSON - MVC6

by Admin 5. May 2016 00:00

I got a situation where we need to dynamically render multiple partial views and bid on the view in MVC6

So Here is the solution.

This is the common method for rendering the partial views as strings

protected string RenderPartialViewToString(string viewName, object model)

        {

            if (string.IsNullOrEmpty(viewName))

                viewName = ActionContext.ActionDescriptor.Name;

 

            ViewData.Model = model;

 

            using (var sw = new StringWriter())

            {

                var engine = Resolver.GetService(typeof(ICompositeViewEngine))

                    as ICompositeViewEngine;

                var viewResult = engine.FindPartialView(ActionContext, viewName);

 

                var viewContext = new ViewContext(

                    ActionContext,

                    viewResult.View,

                    ViewData,

                    TempData,

                    sw,

                    new HtmlHelperOptions()

                );

                //Everything is async now!

                var t = viewResult.View.RenderAsync(viewContext);

                t.Wait();

                return sw.GetStringBuilder().ToString();

            }

        }

 

Here is the method for the view which returns multiple partial view results as JSON

public async Task<ActionResult> GetMultiplePartialsAsync(Your input parameters go here)

        {

            var viewModel = await _myService.FetchDatasAsync(Your input parameters go here);

   //For brevity I am assigning the same view model to all the partial views.

   //You can have sub models in the view model too

                var json = Json(new

                {

                    FilterPartialViewHtml = RenderPartialViewToString("PagedResults", viewModel),

                    CountriesPartialViewHtml = RenderPartialViewToString("Countries", viewModel),

                    NamesPartialViewHtml = RenderPartialViewToString("Names", viewModel)

                });

                return json;

 

        }

 

Here is my View which load all the 3 partial views on load & on click of a checkbox

Note that the paritals are loaded on load as well as gets reladed on all onchange events of the checkbox for countries & Names

@model ResultViewModel

@{

    Layout = "~/Views/Shared/_DemoLayout.cshtml";

}

<div id="wrapper">

    <main id="content" role="main">

            

            <div class="filtering">

                <div class="filter-form">

                    <div class="inner-block">

                        <form method="get" action="Filter">

                            <div class="filter text-filter">

                                <label class="legend" for="finder-keyword-search">Search</label>

                                <input value="" type="text" name="Keywords" id="Keywords" aria-controls="js-search-results-info" class="text">

                            </div>

                            <div id="divCenturies">

                            </div>

                            <div id="divLastNames">

                            </div>

                        </form>

                    </div>

                </div>

                <div class="js-live-search-results-block">

                    <div class="filtered-results">

                            <div id="searchResults">

                            </div>

                            

                    </div>

                </div>

            </div>

    </main>

</div>

<script>

    var url = '@Url.Action("GetMultiplePartialsAsync", "Search")';

 

    $(window).load(function () {

        SearchData();

        $('#searchResults').hide();

    });

 

    $(document).ready(function () {

        $('#searchResults').hide();

        $('#divCenturies').hide();

        $('#divLastNames').hide();

        $(document).on("change", "input[type=checkbox]", function () {

            SearchData();

        });

 

        $("#Keywords").change(function () {

            SearchData();

        });

        $("#Keywords").keypress(function (e) {

            if ((e.keyCode || e.which) == 13) {

                e.preventDefault();

                SearchData();

            }

        });

    });

 

    function SearchData() {

        $.get(url, { Your input parameters here },

                function (data) {

                    $("#searchResults").html(data.FilterPartialViewHtml);

                    $("#divCenturies").html(data.CountriesPartialViewHtml);

                    $("#divLastNames").html(data.NamesPartialViewHtml);

                });

        $('#searchResults').show();

        $('#divCenturies').show();

        $('#divLastNames').show();

    }

</script>

 

Tags:

.NET core features

by Admin 7. April 2016 02:26

 

.NET core

DNX – Dot Net Execution Environment

Native process for hosting the CLR (dnx.exe)

Includes compiler and xpat tools for building .NET apps

Xpat/ OSS friendly project system (project.json)

Package based (install, restore, pack)

Side by side versioning (Manage DNX’s with the .Net Version Manager (DNVM)

Rosyln compiler  

Tags:

Angular2 Stuff

by Admin 1. April 2016 02:13


Angular2 Style guide 

https://angular.io/styleguide

IDE to use

Visual studio code

https://code.visualstudio.com/docs/introvideos/overview

Other Nice Editors 

1. Atom: https://atom.io/ (Free editor, created by the Github guys. Allows you to add plugins and change appearance with third-party packages)

2. Sublime: https://www.sublimetext.com/ (very modular. Allows you to add plugins and change appearance with third-party packages.)

TypeScript

TypeScript is the language of choice for Angular 2 development. It’s a superset to JavaScript which gets compiled into plain JavaScript. The main feature it

adds are the Types, which make development easier (autocompletion etc.) and less error-prone (compiler errors).

Visual studio code nice intro videos which has got Typescript debugging

https://code.visualstudio.com/docs/introvideos/overview?utm_expid=101350005-29.Dor1By5yTmynP2dmCMGGtw.1&start=true

Tags:

TextBox

Tag cloud

    RecentPosts