Friday, 28 April 2017

How to automate Jenkins build with Github

Automate Build Process

Using Jenkins and Git

These days automating the builds is a commonly observed practice, not only  it saves efforts  and time of a developer, but takes care of updating your server with the latest available code .

Let’s hit our innovation engine this time to make Jenkins team up with Git repo.

Plan of Action -

1. Developer check-ins the code, in Git Repo.
2. Jenkins listens to the event occurred.
3. Jenkins initiates the build and creates a war (in this example).
4. The war is later deployed onto the Apache Tomcat server running.

Requirements -

1. Project on Github. Here for example -

A simple project with a jsp - helloWorld.jsp.

<h3 style="color: blue"> Message from the project</h3>

2. Tomcat installed. Here I have installed it at this location - /home/jenkins/apache-tomcat-7.0.77, on my Fedora OS.

Start the tomcat server, for this example we have selected port 8081.

3. Download jenkins  and make it up and running.

For Fedora, I used the following commands -
sudo dnf install jenkins // installs
sudo service jenkins start / stop // kicks on/off
sudo chkconfig jenkins on // to monitor

Time to execute -

Once you successfully install Jenkins locally, please refer to the config changes required on the Jenkins dashboard @ localhost:8080. In case you are stuck anywhere take help of the below screenshot. It has the config I have used for this example.

Outcome -

Now whenever any commit is made in the git repo, the build will be triggered, and latest war will be deployed on the Tomcat server.

Please note - In case tomcat requires a user to be created, as the below line in - apache-tomcat-7.0.77/conf/tomcat-users.xml

<user username="admin" password="admin" roles="manager-script"/>

So here you go, tell at your workplace that you will take care of automating the builds, and enjoy :)

Happy coding !!

Thursday, 20 April 2017

How to use AWS Lambda to send SES notification email w.r.t. S3 events

AWS Lambda + SES notification +S3 events

Image title

Hello Buddies.
Sometimes we want to get notifications when an event occurs in AWS S3 bucket like a file upload, deletion, etc.
For the same the event handling capability of AWS Lambda can come handy, and we will involve SES (Amazon Simple Email Service) in this demo.

To realize this, we will follow the following simple steps -

1.    Have an S3 bucket in place -
It will look like as follows -

Here for example sake, we will use the bucket listed as ‘namit’.

2.    Next comes the lambda function for playing its role, of an event listener -
Lambda     -->    New function

3.    You can refer to the below code for replacing the Lambda template (Node js) -

var aws = require('aws-sdk');

var ses = new aws.SES({

    region: 'us-west-2'


const s3 = new aws.S3({
    apiVersion: '2006-03-01'

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

    console.log("Incoming: ", event);

    const bucket = event.Records[0];

    const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));

    const news = `Event took place in - ${bucket} -> ${key}`;

    const params = {

        Bucket: bucket,

        Key: key,


    var eParams = {

        Destination: {

            ToAddresses: [""]


        Message: {

            Body: {

                Text: {

                    Data: `${news}`



            Subject: {

                Data: "Email Notification"



        Source: ""


    console.log('===SENDING EMAIL===');

    var email = ses.sendEmail(eParams, function(err, data) {

        if (err) console.log(err);

        else {

            console.log("===EMAIL SENT===");

            // console.log(data);

            console.log("EMAIL CODE END");

            console.log('EMAIL: ', email);





Make sure you replace the email id with the one you intent to use. 
A brief look at the configuration and trigger for the lambda -

When enabled, Lambda function will start receiving the event notifications from the S3 it is bound too.

Alongwith the above code some policy and permission changes are required as well.
For the above sample, we can use the below policy structure, in IAM -

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "ses:SendEmail", "ses:SendRawEmail" ], "Resource": "*" } ] }

And make sure the email ID we are using should be verified first in SES -

Uploading a sample file in the S3 bucket 'namit' -> green.jpg

Check the cloudwatch and the email account used.

We have got the mail with -

Subject    : Email Notification
Body        : Event took place in - namit -> green.jpg

Let’s disable the lambda function now, and give a new try with some different use case. :)

Happy Coding!!

Tuesday, 11 April 2017


Hello Buddies

Sharing a document, I prepared for a small integration of AWS Lambda and AWS API Gateway.

Do try it, and share your experience.

Happy Coding !!

AWS Lambda API by namit on Scribd

Featured post

JAVA based project, that can be used to hit DB using JDBC, from WSO2 ESB

Hi Buddies, Here is a small project that will enable you to hit MySQL DB using WSO2 ESB -

Popular Posts