DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Serverless Architecture (Part 1)

Serverless Architecture (Part 1)

Serverless: You know it, you love it, so learn more about it. Let's take a walk through how serverless breaks down units of work and configuring AWS Lambda.

Abhishek Giri user avatar by
Abhishek Giri
·
Apr. 22, 17 · Tutorial
Like (5)
Save
Tweet
Share
11.70K Views

Join the DZone community and get the full member experience.

Join For Free

Of course, “serverless” doesn’t actually mean that there are no servers required to run new features. It just means that we don’t have to deal with the infrastructure. That means we don’t have to worry about scaling, multi-server communication, and other problems related to distributed systems. Lambdas do everything for us!

Serverless can also mean applications where some amount of server-side logic is still written by the application developer, but unlike traditional architectures, it is run in stateless compute containers that are event-triggered, ephemeral, and fully managed by a third party. These type of services have been previously described as ‘BaaS’ or ‘Backend-as-a-Service’.

Why Use Serverless?

  • No more servers

  • Versatile uses

  • Low cost

  • Less code

  • Scalable and flexible

In the diagram below, the units of work get smaller and smaller. We’ve gone from Monolithic -> Microservices -> Functions

Image title

There are already companies who provides functions as a service. Here are some of these:

  • Amazon – AWS Lambda

  • Microsoft – Azure Functions

  • Auth0 – webtask

  • Iron.io – IronWorker

  • Planet Rational – webscript

There are many other services available, and all of these differ in their technical capabilities and implementations.

Serverless architecture allows us to build pieces of code that do something useful, and at the same time, run quickly without consuming a lot of server resources. But that doesn’t mean that those functions are usable only in small scenarios. Although a function is a small unit, it can be invoked many times per second.

Now that we've gotten the basics and benefits out of the way, let's dive into our example of this series.

AWS Lambda

Image title

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume – there is no charge when your code is not running. With AWS Lambda, you can run code for virtually any type of application or backend service – all with zero administration. AWS Lambda currently supports Node.js, Java, C#, and Python.

You can use AWS Lambda to run your code in response to events, such as changes to data in an Amazon S3 bucket, an Amazon DynamoDB table, etc.

Now we will build a mailer application in Scala and put that application in AWS Lambda with a AWS S3 PutObject trigger.

Step 1:  Create a lambda blank function:

Image title

Step 2: Configure triggers:

Image title

Step 3: Configure the function, choose Java 8 as the language.

Image title


Step 4: Upload your executable JAR and set the environmental variables.

Note: You can find the sample project from here AWS-Lambda-Scala-Mailer

Steps to make an executable jar:

  • git clone https://github.com/knoldus/AWS-Lambda-Scala-Mailer.git
  • cd AWS-Lambda-Scala-Mailer
  • sbt assembly

Image title

Step 5: Set the Lambda function handler and role.

Image title


Then click Next. Your Lambda-scala-mailer is ready! This function will get triggered by S3 actions.

If you find any challenge, let me know in the comments.

Stay tuned for the next blog on serverless. Until then, happy coding!

AWS Architecture AWS Lambda

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Problems of Cloud Cost Management: A Socio-Technical Analysis
  • A Simple Union Between .NET Core and Python
  • Top 10 Secure Coding Practices Every Developer Should Know
  • Asynchronous HTTP Requests With RxJava

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: