serverless applications with AWS Lambda
April 11, 2017 admin 0 Comments

AWS Lambda is a process administration that gives you a chance to run code without provisioning or managing servers. AWS Lambda executes your code just when required and scales consequently, from a couple demands for every day to thousands every second. You pay just for the process time you devour – there is no cost when your code is not in action. With AWS Lambda, you can run code for effectively any sort of backend service or application – not to mention, all with nil organization. AWS Lambda runs your code on a high-accessibility compute foundation and plays out the greater part of the organization of the compute resources, including operating system maintenance and server, automatic scaling and capacity provisioning, code checking and logging. You should simply supply your code in one of the dialects that AWS Lambda bolsters (at present Java, Node.js, Python and C#).

In server less computing, a 3rd-party service provider assumes liability for procedures, servers and operating systems. Now developers can concentrate on simply creating incredible software. They should simply code. Resource contemplation (configure, manage, deploy) is no trouble anymore. The cloud specialist deals with that. The less you are intended to deal with the case, the more server less it is. Server less runs well with specific capacities. It is for organizations to learn to streamline their utilization and incorporate them into more extensive data systems.

Despite the fact that AWS Lambda has been around just since 2014, noteworthy worldwide organizations are now embracing it. The primary elements energizing its notoriety:

  • Product launching time is notably decreased
  • IT costs lessened to a gigantic degree.
  • Organizations don’t need a spending plan for underutilized or squandered computing and engineering capacities.

It suppresses troubles identified with unused employed server limit without bargaining on adaptability or speed of response. New businesses have moved from rigid application design to micro services driven engineering by utilizing AWS Lambda.

You can likewise construct server less applications made out of capacities that are activated by events and consequently send them utilizing AWS CodePipeline and AWS CodeBuild.

Amazon Simple Email Service (Amazon SES)

Amazon SES is an email send/receive administration that gives a simple, financially savvy method for you for emailing.

Amazon Simple Notification Service (Amazon SNS)

Amazon Simple Notification Service (Amazon SNS) is a web administration that empowers end-users, applications, and various devices to instantaneously convey and receive notifications from the cloud.

We have implemented AWS Lambda service using node.js in one of our PHP project. Following diagram exhibits the work-flow:

In order to execute AWS Lambda service in a PHP website development, node.js is essential to utilize. Below are the steps which shows node.js utilization:

Install “Aws-sdk” node.js packages using below command

npm install aws-sdk

Configure “Aws-sdk” packages
var aws_options = {
accessKeyId: 'Your-access-key',
secretAccesskey: 'Your-secret-access-key',
region: 'Your-region',
apiVersion: 'current-date' // Format date("Y-m-d")
};

Send email (SES) using “Aws-sdk”
var params = {
Destination: {/* required */
ToAddresses: ["to-email-address"]
},
Message: {/* required */
Body: {/* required */
Html: {
Data: "message-body", /* required */
Charset: 'UTF-8'
}
},
Subject: {/* required */
Data: "subject", /* required */
Charset: 'UTF-8'
}
},
Source: 'from-name', /* required from email address */
ReplyToAddresses: ["from-email-address"],
ReturnPath: "from-email-address", // required for bounce handle
ReturnPathArn: "email-address-arn", //verfied email address arn
SourceArn: "email-address-arn",
};
var response = new AWS.SES(aws_options);
response.sendEmail(params, function (err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else
console.log(data);           // successful response
});

Send text message (SNS) using “Aws-sdk”
var params = {
Message: "text-body", /* required */
MessageAttributes: {
DefaultSenderID: {
DataType: 'String', /* required */
StringValue: 'string-value'
},
'DefaultSMSType': {
DataType: 'String', /* required */
StringValue: 'Transactional'
}
/* anotherKey: ... */
},
// MessageStructure: 'STRING_VALUE',
PhoneNumber: "to-phone-number",
};
var response = new AWS.SNS(aws_options);
response.publish(params, function (err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else
console.log(data); // successful response
});
}