Here are some tips and tricks on how to update an existing AWS ECS deployment.

NOTICE: This post assume that you have some knowledge on AWS, scripting, docker and Bitbucket.

The scripts and guide below will do the following:

Clone external libraries needed for your project (Assumes that you have a multi-project application

Build your application

Build the docker image

Push the docker image into Elastic Container Service own container registry

Stop all tasks in a cluster to force the associated services to restart the tasks

I am using this method of deploying to avoid making constant new task definitions. I find that unnecessary. My view is to have a deployment docker tag that your target service task definitions use. In this way you only make sure that you have one good task definition that you plan to you. If needed later update your task definition and service to use it. This deployment suggestion will not care of any other detail that except the docker image and cluster name.

Then test your API or Web App in the cloud with some 3rd party tool in this case I am using Postman collection, Postman Environmental Settings and Newman

The above steps can be performed automatically when you make changes to a branch or manually from the commit view or branches view (on the row with the branch or commit id move you mouse on top of “…” to get the option “Run pipeline for a branch” and selected the manual pipeline option)

Needed steps:

Create/have an IAM access keys for deployment into ECS and ECR from Bitbucket.

Generate SSH keys in the Bitbucket repository where you plan to run your pipeline

If you have any depended Bitbucket repositories copy the Public Key in Step 2 into that repository settings.

Then in the primary repository from which you plan to deploy set environmental variables needed for the deployment.

Create you pipeline with the example Bitbucket pipeline definition file and supplement scripts.

Step 1: AWS Access

You will need an access key/secrect to AWS with the following minimum policy settings:

Step 3: Other repositories (Optional)

If you want your Pipelines builds to be able to access a different Bitbucket repository (other than the repo where the builds run):

Add an SSH key to the settings for the repo where the build will run, as described in Step 1 above (you can create a new key in Bitbucket Pipelines or use an existing key).

Add the public key from that SSH key pair directly to settings for the other Bitbucket repo (i.e. the repo that your builds need to have access to).
See Use access keys for details on how to add a public key to a Bitbucket repo.

Step 4: Setting up environmental variables

APPIMAGE_TESTENV_CLUSTER : The cluster name where to which the docker image is deployed to in this case a test environment that is manually triggered

APPIMAGE_DEVENV_CLUSTER: A dev target cluster that is associated with the master branch and starts automatically

APPIMAGE_NAME: The docker image name (Notice: Must match the one in your service -> task definition)

APPIMAGE_TAG: the docker image tag The docker image name (Notice: Must match the one in your service -> task definition)

AWS_ACCESS_KEY_ID (SECURE)

AWS_SECRET_ACCESS_KEY (SECURE)

AWS_DEFAULT_REGION : The region where your cluster is located

REGISTRYNAME : The ECR registry name wherethe image is to be pushed

Step 5: Bitbucket Pipeline

Pipeline definitions

The sample pipeline script has two options:
* Custom/manual deployment in the custom section of the script
* Branches/automatic deployment in the branches section of the script

Testing a response for success and body content

// example using pm.response.to.be*
pm.test("response must be valid and have a body", function () {
// assert that the status code is 200
pm.response.to.be.ok; // info, success, redirection, clientError, serverError, are other variants
// assert that the response has a valid JSON body
pm.response.to.be.withBody;
pm.response.to.be.json; // this assertion also checks if a body exists, so the above check is not needed
});
console.log("BODY:" + responseBody);

#Notice: In python you differentiate between blocks of code by whitespace, or a tab. Not the same as let say Java or C# where the char { and } are used to differentiate a block of code. Pay attention to you formatting, indentation.

#Notice: The char , (comma) is used to tell that something is going to continue on the same print line, within the same block of code. See example above.

#Notice: Colons : differentiate clauses.

Importing modules

import numpy as np

A = np.random.normal(25.0, 5.0, 10)

print A

Data structures

Lists

Defining a list(Notice: The brackets [] define an mutable list):

x = [1, 2, 3, 4, 5, 6]

Printing the length of a list:

print len(x)

Sub setting lists:

First 3 elements(counting starts from zero):

x[:3]

Last 3 elements:

x[3:]

Last two elements from starting from the end of the list:

x[-2:]

Extend the list with a new list :

x.extend([7,8])

Add a new item to the list:

x.append(9)

Python is a weekly typed language which allows you to put whatever you want in a list:

Creating a multidimensional list:

y = [10, 11, 12]

listOfLists = [x, y]

listOfLists

Sort a list(descending):

z = [3, 2, 1]

z.sort()

Sort a list(ascending):

z.sort(reverse=True)

Tuples

Are just like lists but immutable.

You can not extend them append them, sort them etc. You can not change them.

Example:

#Tuples are just immutable lists. Use () instead of []

x = (1, 2, 3)

len(x)

y = (4, 5, 6)

listOfTuples = [x, y]

Tuples common usage for data science or data processing:

Is to use it to assign variables to input data that as it is read in.

This example creates variable with values from a “source” where data is split by the comma.

#Notice: It is important that you have the same about of variables in your tuple as you are retrieving/assigning from the data “source”.

(age, income) = “32,120000”.split(‘,’)

print age

print income

Dictionaries

A way to define a “lookup” table:

# Like a map or hash table in other languages

captains = {}

captains[“Enterprise”] = “Kirk”

captains[“Enterprise D”] = “Picard”

captains[“Deep Space Nine”] = “Sisko”

captains[“Voyager”] = “Janeway”

print captains[“Voyager”]

print captains.get(“Enterprise”)

for ship in captains:

print ship + “: ” + captains[ship]

If something is not found the result will be none:

print captains.get(“NX-01”)

Functions

Let you repeat a set of operation over and over again with different parameters.

Notice: use def to define a function and () chars to define the parameters and use the return keyword to return value from the function.

def SquareIt(x):

return x * x

print SquareIt(2)

Pass functions around as parameters

#Notice: You have to make sure that what you are typing is correct because there is no strong typing in Python. Typing the wrong function name will cause errors.

#You can pass functions around as parameters

def DoSomething(f, x):

return f(x)

print DoSomething(SquareIt, 3)

Lambda functions

Is Functional programming: You can inline a function into a function

#Notice: lambda keyword is telling that you are defining a inline function to be used where you put it. In the example below inside a function parameter named x followed by a colon : character followed by what the function actually does. To pass in multiple parameters to a lambda function use the comma , to separate the variables.

Ok, this is probably a quite simple thing to do and maybe everyone knows it BUT just in case… :).

Well, you need two things a C# code(or some other way to ouput HTML) to generate and anchor link by which to display or hide a given HTML element.

In this case, let’s say that you have a DIV element. You assign as the ID value the client ID which your control receives from ASP .NET(notice that the unique ID or the ID but the ClientID, it is HTML friendly).

Then you would do something like the code below. You are calling a JavaScript function which receives as parameters the full ID for the DIV element and the start of the DIV full id.

The idea is to be able to identify all of the elements which are under this same hide and show logic while still being able to identify a single item.

Exmaple ID:
id =”cars_ASP.NETUserControlClientID_carnumber”

The bolded part would be used to identify ALL of the items which need be processed at the same time. While the non-bolded value(carnumber) is the identifier for a single item.

The C# code below creates an anchor calling the function below the C# code. Notice the href definition “javascript:void(0)“, this is to avoid page jump in certain browsers and their versions.

I created a script that might help someone out there who wants to backup their SharePoint solution packages. This script is able to export specific solutions or all if no solution names are passed to the script.

Sample script calling for specific solutions:

.\script.ps1 –Solutions MYWSPNUM1.wsp,MYWSPNUM2.wsp

Or if you want to export all available solutions then simply call the script without any parameters: