{"id":2464,"date":"2017-01-06T10:39:59","date_gmt":"2017-01-06T10:39:59","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2464"},"modified":"2023-05-19T04:12:27","modified_gmt":"2023-05-19T11:12:27","slug":"serverless-faas-aws-lambda-java","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/","title":{"rendered":"Serverless FaaS With AWS Lambda and Java"},"content":{"rendered":"<h2>What is a Serverless Architecture?<\/h2>\n<p>Serverless architecture runs\u00a0custom code in ephemeral containers\u00a0that are fully managed by a 3rd party. The custom code is typically a small part of a complete application. It is also called as\u00a0<em>function<\/em>. This gives another name for serverless architecture as\u00a0<em>Function as a Service<\/em> (FaaS). The container is ephemeral because it may only last for one invocation. The container may be reused but that&#8217;s not something you can rely upon. As a developer, you upload the code to FaaS platform, the service then handles all the capacity, scaling, patching and administration of the\u00a0infrastructure to run your code.<\/p>\n<p>An application built using Serverless Architecture follows the event-driven approach. For example, an activity happened in the application such as a click. This is very different from a classical architecture where the application code is typically deployed in an application server such as Tomcat or WildFly. Scaling your application means starting additional instances of the application server or spinning up additional containers with the packaged application server. The Load Balancer need to be updated with the new IP addresses. Operating systems need to be patched, upgraded and maintained.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/martinfowler.com\/articles\/serverless\/ps.svg\" alt=\"\" width=\"493\" height=\"125\" \/><\/p>\n<p><a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\">Serverless Architectures<\/a> explain the difference between the classical programming model and this new serverless architecture. With a FaaS platform your application is divided into multiple functions. Each function is deployed in FaaS. The service spins up additional compute instances to meet the scalability demands of your application. FaaS platforms provides the execution environment and takes care of starting and tearing down\u00a0the containers to run your function.<\/p>\n<p><a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/martinfowler.com\/articles\/serverless\/sps.svg\" alt=\"\" width=\"489\" height=\"305\" \/><\/a><\/p>\n<p>Read <a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\">Serverless Architectures<\/a> for more details about these images. One of the big advantages of FaaS is that you are only charged for the compute time, i.e. the time your code is running. There is no charge when your code is not running. How are Functions different from VMs and Containers?<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2616\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/01\/vm-containers-serverless.png\" alt=\"\" width=\"1920\" height=\"1101\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless.png 1920w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-300x172.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-1024x587.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-768x440.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-1536x881.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-20x11.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/01\/vm-containers-serverless-1320x757.png 1320w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>Note that Linux containers instead of Docker containers are used\u00a0as an implementation for AWS Lambda.<\/p>\n<h2>How is FaaS Different From PaaS?<\/h2>\n<p>As quoted at <a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\">Serverless Architectures<\/a>, a quick answer is provided by the following tweet:<\/p>\n<blockquote class=\"twitter-tweet\">\n<p dir=\"ltr\">If your PaaS can efficiently start instances in 20ms that run for half a second, then call it serverless. <a href=\"https:\/\/t.co\/S3YzvqFYLR\">https:\/\/t.co\/S3YzvqFYLR<\/a><\/p>\n<p>\u2014 adrian cockcroft (@adrianco) <a href=\"https:\/\/twitter.com\/adrianco\/status\/736553530689998848\">May 28, 2016<\/a><\/p><\/blockquote>\n<p>In other words most PaaS applications are not geared towards bringing entire applications up and down for every request, whereas FaaS platforms do exactly this. <a href=\"https:\/\/serverless.zone\/abstracting-the-back-end-with-faas-e5e80e837362\">Abstracting the Back-end with FaaS<\/a> explain the difference with different\u00a0*aaS offerings. The image from the blog is captured below:<br \/>\n<a href=\"https:\/\/serverless.zone\/abstracting-the-back-end-with-faas-e5e80e837362\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14464\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/faas.png\" alt=\"faas\" width=\"778\" height=\"375\" \/><\/a><\/p>\n<p><a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\">Serverless Architectures<\/a>\u00a0also provide great\u00a0details about what\u00a0FaaS is and is not. <a href=\"https:\/\/aws.amazon.com\/lambda\/\">AWS Lambda<\/a>, <a href=\"https:\/\/cloud.google.com\/functions\/\">Google Cloud Functions <\/a>and <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/functions\/\">Azure Functions<\/a>\u00a0are some of the options for running serverless\u00a0applications. This blog will show how to\u00a0write your first AWS Lambda function.<\/p>\n<h2>What is AWS Lambda?<\/h2>\n<p>AWS Lambda is a FaaS service from Amazon Web Services. It runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. AWS Lambda charges you for the duration your code runs in increments of 100ms. There is no cost associated with storing the Lambda function in AWS.<\/p>\n<p>First million requests per month are free and the pricing after that is nominal. Read more details on <a href=\"https:\/\/aws.amazon.com\/lambda\/pricing\/\">Lambda pricing<\/a>.\u00a0It also provides visibility into performance by providing real time metrics and logs to <a href=\"https:\/\/aws.amazon.com\/cloudwatch\/\">AWS CloudWatch<\/a>. All you need to do is write the code! Here is a quick introduction:<\/p>\n<p>Also check out What&#8217;s New in AWS Lambda from <a href=\"https:\/\/reinvent.awsevents.com\/\">AWS ReInvent 2016<\/a>:<\/p>\n<p>Also checkout Serverless Architectural Patterns and Best Practices from AWS ReInvent 2016:<\/p>\n<p>The code you run on AWS Lambda is called a Lambda Function. You upload your code as a zip file or design it using the <a href=\"https:\/\/console.aws.amazon.com\/lambda\/home\">AWS Lambda Management Console<\/a>. There is a built-in support for AWS SDK and this simplifies the ability to call other AWS services. In short,\u00a0Lambda is scalable, serverless, compute in the cloud. AWS Lambda provides several\u00a0<a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/current-supported-versions.html\">execution environments:<\/a><\/p>\n<ul>\n<li>Node.js \u2013 v0.10.36, v4.3.2 (recommended)<\/li>\n<li>Java \u2013 Java 8<\/li>\n<li>Python \u2013 Python 2.7<\/li>\n<li>.NET Core \u2013 .NET Core 1.0.1 (C#)<\/li>\n<\/ul>\n<p>This blog will show how to:<\/p>\n<ul>\n<li>Build a Java application that stores a JSON document to Couchbase<\/li>\n<li>Use Maven to\u00a0create a deployment package for Java application<\/li>\n<li>Create a Lambda Function<\/li>\n<li>Update the Lambda Function<\/li>\n<\/ul>\n<p>The complete code in this blog is available at\u00a0<a href=\"https:\/\/github.com\/arun-gupta\/serverless\/tree\/master\/aws\/hellocouchbase\">github.com\/arun-gupta\/serverless\/tree\/master\/aws\/hellocouchbase<\/a>.<\/p>\n<h2>Java Application for AWS Lambda<\/h2>\n<p>First, let&#8217;s look at a Java application that will be used for this Lambda function. <a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/java-programming-model.html\">Programming Model for Lambda Functions in Java<\/a> provide more details about how to\u00a0write your\u00a0Lambda function code in Java. Our Lambda function will implemented\u00a0the pre-defined interface <code>com.amazonaws.services.lambda.runtime.RequestHandler<\/code>. The code looks like:<\/p>\n<pre class=\"lang:default decode:true\">public class HelloCouchbase implements RequestHandler&lt;Request, String&gt; {\r\n\r\n    CouchbaseCluster cluster;\r\n    Bucket bucket;\r\n    LambdaLogger logger;\r\n\r\n    @Override\r\n    public String handleRequest(Request request, Context context) {\r\n        SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss.SSS\");\r\n        String timestamp = dateFormat.format(Calendar.getInstance().getTime());\r\n\r\n        logger = context.getLogger();\r\n        logger.log(\"Request received: %s\" + timestamp);\r\n        ButtonDocument buttonDocument = new ButtonDocument();\r\n        buttonDocument.setId(context.getAwsRequestId());\r\n        buttonDocument.setRequestId(context.getAwsRequestId());\r\n        buttonDocument.setTimestamp(String.valueOf(timestamp));\r\n        \r\n        getBucket().upsert(buttonDocument.toJson());\r\n\r\n        return buttonDocument.toString();\r\n    }<\/pre>\n<p><code>handleRequest<\/code> method is where the function code is implemented. <code><a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/java-context-object.html\">Context<\/a><\/code> provides useful information about the Lambda execution environment. Some of the information from the context is stored a JSON document.\u00a0Finally,\u00a0<a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/sdk\/java\/start-using-sdk.html\">Couchbase Java SDK<\/a>\u00a0API <code>upsert<\/code> is used to write a JSON document to the identified Couchbase instance.\u00a0<a href=\"https:\/\/www.couchbase.com\/blog\/database-on-amazon-installing-couchbase-ami-on-aws\/\">Couchbase on Amazon EC2<\/a> provides complete instructions to install Couchbase on AWS EC2. Information about the Couchbase server is obtained as:<\/p>\n<pre class=\"lang:default decode:true\">public CouchbaseCluster getCluster() {\r\n    if (null == cluster) {\r\n        logger.log(\"env: \" + System.getenv(\"COUCHBASE_HOST\"));\r\n        cluster = CouchbaseCluster.create(System.getenv(\"COUCHBASE_HOST\"));\r\n    }\r\n    return cluster;\r\n}<\/pre>\n<p>This is once again using Couchbase Java API\u00a0<a href=\"https:\/\/docs.couchbase.com\/sdk-api\/couchbase-java-client-2.3.6\/com\/couchbase\/client\/java\/CouchbaseCluster.html\">CouchbaseCluster<\/a>\u00a0as a main entry point to the Couchbase cluster. The <code>COUCHBASE_HOST<\/code> environment variable is passed when the Lambda function is created. In our case, this would point to\u00a0a\u00a0single node Couchbase cluster running on AWS EC2.\u00a0<a href=\"https:\/\/aws.amazon.com\/about-aws\/whats-new\/2016\/11\/aws-lambda-supports-environment-variables\/\">Environment variables were recently introduced<\/a> in AWS Lambda. Finally, you need to access this bucket in the server:<\/p>\n<pre class=\"lang:default decode:true\">public Bucket getBucket() {\r\n    while (null == bucket) {\r\n        logger.log(\"Trying to connect to the database\");\r\n        bucket = getCluster().openBucket(\"serverless\", 2L, TimeUnit.MINUTES);\r\n\r\n        try {\r\n            Thread.sleep(3000);\r\n        } catch (Exception e) {\r\n            logger.log(\"Thread sleep Exception: \" + e.toString());\r\n            throw new RuntimeException(e);\r\n        }\r\n    }\r\n\r\n    return bucket;\r\n}<\/pre>\n<p>The bucket name is <code>serverless<\/code> and all JSON\u00a0documents are stored in this. A simple <a href=\"https:\/\/github.com\/arun-gupta\/serverless\/tree\/master\/aws\/helloworld\">Hello World application<\/a> may be used for creating this function as well.<\/p>\n<h2>Create AWS Lambda Deployment Package<\/h2>\n<p>AWS FaaS needs a deployment package. This Lambda package is either a <code>.zip<\/code> or <code>.jar<\/code> file that contains all the dependencies of the function. Our application is packaged using Maven, and so we&#8217;ll use a Maven plugin to create\u00a0a deployment package. The application has <code>pom.xml<\/code> with the following plugin fragment:<\/p>\n<pre class=\"lang:default decode:true\">    org.apache.maven.plugins\r\n    maven-shade-plugin\r\n    2.3\r\n    \r\n        false\r\n    \r\n    \r\n        \r\n            package\r\n            \r\n                shade\r\n            \r\n        \r\n    \r\n<\/pre>\n<p>More details about Maven configuration are available in <a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/java-create-jar-pkg-maven-no-ide.html\">Creating a .jar Deployment Package Using Maven without any IDE<\/a>.\u00a0The <a href=\"https:\/\/maven.apache.org\/plugins\/maven-shade-plugin\/\">maven-shade-plugin<\/a> allows you to create an uber-jar including all the dependencies. The <code>shade<\/code> goal is tied to the <code>package<\/code> phase. So the <code>mvn package<\/code> command will generate a single deployment jar. Package the application using the <code>mvn package<\/code> command. This will\u00a0show the output:<\/p>\n<pre class=\"lang:default decode:true\">[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hellocouchbase ---\r\n[INFO] Building jar: \/Users\/arungupta\/workspaces\/serverless\/aws\/hellocouchbase\/hellocouchbase\/target\/hellocouchbase-1.0-SNAPSHOT.jar\r\n[INFO] \r\n[INFO] --- maven-shade-plugin:2.3:shade (default) @ hellocouchbase ---\r\n[INFO] Including com.amazonaws:aws-lambda-java-core:jar:1.1.0 in the shaded jar.\r\n[INFO] Including com.couchbase.client:java-client:jar:2.3.6 in the shaded jar.\r\n[INFO] Including com.couchbase.client:core-io:jar:1.3.6 in the shaded jar.\r\n[INFO] Including io.reactivex:rxjava:jar:1.1.8 in the shaded jar.\r\n[INFO] Replacing original artifact with shaded artifact.\r\n[INFO] Replacing \/Users\/arungupta\/workspaces\/serverless\/aws\/hellocouchbase\/hellocouchbase\/target\/hellocouchbase-1.0-SNAPSHOT.jar with \/Users\/arungupta\/workspaces\/serverless\/aws\/hellocouchbase\/hellocouchbase\/target\/hellocouchbase-1.0-SNAPSHOT-shaded.jar\r\n[INFO] ------------------------------------------------------------------------\r\n[INFO] BUILD SUCCESS\r\n[INFO] ------------------------------------------------------------------------<\/pre>\n<p>The <code>target\/hello-couchbase-1.0-SNAPSHOT.jar<\/code> is the shaded jar that will be deployed to AWS Lambda. More details about creating a\u00a0deployment\u00a0package are at <a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/lambda-java-how-to-create-deployment-package.html\">Creating a Deployment Package<\/a>.<\/p>\n<h2>Create AWS Lambda Function<\/h2>\n<p>Create an AWS Lambda Function using <a href=\"https:\/\/aws.amazon.com\/cli\/\">AWS CLI<\/a>.\u00a0The CLI command in this case looks like:<\/p>\n<pre class=\"lang:default decode:true\">aws lambda create-function \r\n--function-name HelloWorld \r\n--role arn:aws:iam:::role\/service-role\/myLambdaRole \r\n--zip-file fileb:\/\/\/Users\/arungupta\/workspaces\/serverless\/aws\/hellocouchbase\/hellocouchbase\/target\/hellocouchbase-1.0-SNAPSHOT.jar \r\n--handler org.sample.serverless.aws.couchbase.HelloCouchbaseLambda \r\n--description \"Hello Couchbase Lambda\" \r\n--runtime java8  \r\n--region us-west-2 \r\n--timeout 30 \r\n--memory-size 1024 \r\n--publish<\/pre>\n<p>In this CLI:<\/p>\n<ul>\n<li><code>create-function<\/code> creates a Lambda function<\/li>\n<li><code>--function-name<\/code> provides the function name. The function name is case sensitive.<\/li>\n<li><code>--role<\/code> specifies Amazon Resource Name (ARN) of an <a href=\"https:\/\/console.aws.amazon.com\/iam\/home?#\/roles\">IAM role<\/a> that Lambda assumes when it executes your function to access any other AWS resources. If you&#8217;ve executed a Lambda<br \/>\nfunction using AWS Console then this role is\u00a0created for you.<\/li>\n<li><code>--zip-file<\/code> points to the deployment package that was created in the previous step. <code>fileb<\/code>\u00a0is an AWS CLI specific protocol to indicate that the content uploaded is binary.<\/li>\n<li><code>--handler<\/code>\u00a0is the Java class that is called to begin\u00a0execution of the function<\/li>\n<li><code>--publish<\/code> request AWS Lambda to create the Lambda function and publish a version as an atomic operation. Otherwise multiple versions may be created and may be published at a later point.<\/li>\n<\/ul>\n<p>Lambda Console shows:<\/p>\n<p><a href=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/servleress-couchbase-lambda-function-1024x629.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-14472\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/servleress-couchbase-lambda-function-1024x629.png\" alt=\"servleress-couchbase-lambda-function\" width=\"604\" height=\"371\" \/><\/a><\/p>\n<h2>Test AWS Lambda Function<\/h2>\n<p>Test the AWS Lambda Function using AWS CLI.<\/p>\n<pre class=\"lang:default decode:true\">aws lambda invoke \r\n--function-name HelloCouchbaseLambda \r\n--region us-west-2 \r\n--payload '' \r\nhellocouchbase.out<\/pre>\n<p>It shows the output as:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"StatusCode\": 200\r\n}<\/pre>\n<p>The output from the command is stored in <code>hellocouchbase.out<\/code> and looks like:<\/p>\n<pre class=\"lang:default decode:true\">\"{\"id\":\"e6bbe71a-ca4f-11e6-95a7-95f2ed410493\",\"installationId\":null,\"requestId\":\"e6bbe71a-ca4f-11e6-95a7-95f2ed410493\",\"identityId\":null,\"timestamp\":\"2016-12-25 03:12:01.157\"}\"<\/pre>\n<p>Invoking this function stores a\u00a0JSON\u00a0document in Couchbase. Documents stored in Couchbase can be seen using\u00a0<a href=\"https:\/\/docs.couchbase.com\/server\/6.0\/manage\/management-tools.html\">the Couchbase Web Console<\/a>. The username is <code>Administrator<\/code> and the password is the EC2 instance id. All data buckets in this Couchbase instance are shown below:<\/p>\n<p><a href=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-overview-1024x321.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-14468\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-overview-1024x321.png\" alt=\"serverless-couchbase-bucket-overview\" width=\"604\" height=\"189\" \/><\/a><\/p>\n<p>Note that the <code>serverless<\/code> bucket is\u00a0manually created. Clicking on Documents shows details of\u00a0different documents stored in the bucket:<\/p>\n<p><a href=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-documents-1024x500.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-14469\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-documents-1024x500.png\" alt=\"serverless-couchbase-bucket-documents\" width=\"604\" height=\"295\" \/><\/a><\/p>\n<p>Clicking on each document shows more details about the JSON\u00a0document:<\/p>\n<p><a href=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-document-1024x608.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-14470\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-bucket-document-1024x608.png\" alt=\"serverless-couchbase-bucket-document\" width=\"604\" height=\"359\" \/><\/a><\/p>\n<p>Lambda function can also be tested using the Console:<\/p>\n<p><a href=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-console-test-1024x427.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-14473\" src=\"\/wp-content\/original-assets\/december-2016\/serverless-faas-with-aws-lambda-and-java\/serverless-couchbase-console-test-1024x427.png\" alt=\"serverless-couchbase-console-test\" width=\"604\" height=\"252\" \/><\/a><\/p>\n<h2>Update AWS Lambda Function<\/h2>\n<p>If the application logic changes then\u00a0a new deployment package needs to be uploaded for the Lambda function. In this case, <code>mvn package<\/code> will create a deployment package and <code>aws lambda<\/code> CLI command is used to update the function code:<\/p>\n<pre class=\"lang:default decode:true\">aws lambda update-function-code \r\n--function-name HelloCouchbaseLambda \r\n--zip-file fileb:\/\/\/Users\/arungupta\/workspaces\/serverless\/aws\/hellocouchbase\/hellocouchbase\/target\/hellocouchbase-1.0-SNAPSHOT.jar \r\n--region us-west-2 \r\n--publish<\/pre>\n<p>Shows the result:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"CodeSha256\": \"w510ejw\/OoVsQt2JiLG2bPZPAaFvQCRrYYYlQWctCQE=\", \r\n    \"FunctionName\": \"HelloCouchbaseLambda\", \r\n    \"CodeSize\": 6978108, \r\n    \"MemorySize\": 1024, \r\n    \"FunctionArn\": \"arn:aws:lambda:us-west-2::function:HelloCouchbaseLambda:8\", \r\n    \"Environment\": {\r\n        \"Variables\": {\r\n            \"COUCHBASE_HOST\": \"ec2-35-165-249-235.us-west-2.compute.amazonaws.com\"\r\n        }\r\n    }, \r\n    \"Version\": \"8\", \r\n    \"Role\": \"arn:aws:iam:::role\/service-role\/myLambdaRole\", \r\n    \"Timeout\": 30, \r\n    \"LastModified\": \"2016-12-25T04:17:38.717+0000\", \r\n    \"Handler\": \"org.sample.serverless.aws.couchbase.HelloCouchbaseLambda\", \r\n    \"Runtime\": \"java8\", \r\n    \"Description\": \"Java Hello Couchbase\"\r\n}<\/pre>\n<p>The function can then be invoked again. During the writing of this blog, this was often used to debug the function as well. This is because Lambda functions do not have any state or box associated with them. And so you cannot log in to a box to check out if the function did not deploy correctly. You can certainly use CloudWatch log statements once the function is working.<\/p>\n<h2>AWS Lambda References<\/h2>\n<ul>\n<li><a href=\"https:\/\/martinfowler.com\/articles\/serverless.html\">Serverless Architectures<\/a><\/li>\n<li><a href=\"https:\/\/docs.aws.amazon.com\/lambda\/latest\/dg\/lambda-introduction.html\">AWS Lambda: How it works<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/home\/server.html\">Couchbase Server Docs<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/forums\/\">Couchbase Forums<\/a><\/li>\n<li>Follow us at <a href=\"https:\/\/twitter.com\/couchbasedev\">@couchbasedev<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is a Serverless Architecture? Serverless architecture runs\u00a0custom code in ephemeral containers\u00a0that are fully managed by a 3rd party. The custom code is typically a small part of a complete application. It is also called as\u00a0function. This gives another name [&hellip;]<\/p>\n","protected":false},"author":58,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816],"tags":[],"ppma_author":[8933],"class_list":["post-2464","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Is AWS Lambda PaaS | How is FaaS Different from PaaS<\/title>\n<meta name=\"description\" content=\"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Serverless FaaS With AWS Lambda and Java\" \/>\n<meta property=\"og:description\" content=\"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-06T10:39:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-19T11:12:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/martinfowler.com\/articles\/serverless\/ps.svg\" \/>\n<meta name=\"author\" content=\"Arun Gupta, VP, Developer Advocacy, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@arungupta\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arun Gupta, VP, Developer Advocacy, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\"},\"author\":{\"name\":\"Arun Gupta, VP, Developer Advocacy, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/39d8caed0f536489b6aa6e8d31ee631f\"},\"headline\":\"Serverless FaaS With AWS Lambda and Java\",\"datePublished\":\"2017-01-06T10:39:59+00:00\",\"dateModified\":\"2023-05-19T11:12:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\"},\"wordCount\":1480,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Couchbase Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\",\"name\":\"Is AWS Lambda PaaS | How is FaaS Different from PaaS\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2017-01-06T10:39:59+00:00\",\"dateModified\":\"2023-05-19T11:12:27+00:00\",\"description\":\"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Serverless FaaS With AWS Lambda and Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/39d8caed0f536489b6aa6e8d31ee631f\",\"name\":\"Arun Gupta, VP, Developer Advocacy, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8900a75409c646948fe0bd80f6240337\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f912e10b5f39748ee4f1a0b0da6f42747f0b3a94fe7acb511791468656f5e726?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f912e10b5f39748ee4f1a0b0da6f42747f0b3a94fe7acb511791468656f5e726?s=96&d=mm&r=g\",\"caption\":\"Arun Gupta, VP, Developer Advocacy, Couchbase\"},\"description\":\"Arun Gupta is the vice president of developer advocacy at Couchbase. He has built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. He has deep expertise in leading cross-functional teams to develop and execute strategy, planning and execution of content, marketing campaigns, and programs. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team. Gupta has authored more than 2,000 blog posts on technology. He has extensive speaking experience in more than 40 countries on myriad topics and is a JavaOne Rock Star for three years in a row. Gupta also founded the Devoxx4Kids chapter in the US and continues to promote technology education among children. An author of several books on technology, an avid runner, a globe trotter, a Java Champion, a JUG leader, NetBeans Dream Team member, and a Docker Captain, he is easily accessible at @arungupta.\",\"sameAs\":[\"https:\/\/x.com\/arungupta\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/arun-gupta\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Is AWS Lambda PaaS | How is FaaS Different from PaaS","description":"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/","og_locale":"en_US","og_type":"article","og_title":"Serverless FaaS With AWS Lambda and Java","og_description":"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).","og_url":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-01-06T10:39:59+00:00","article_modified_time":"2023-05-19T11:12:27+00:00","og_image":[{"url":"https:\/\/martinfowler.com\/articles\/serverless\/ps.svg","type":"","width":"","height":""}],"author":"Arun Gupta, VP, Developer Advocacy, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@arungupta","twitter_misc":{"Written by":"Arun Gupta, VP, Developer Advocacy, Couchbase","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/"},"author":{"name":"Arun Gupta, VP, Developer Advocacy, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/39d8caed0f536489b6aa6e8d31ee631f"},"headline":"Serverless FaaS With AWS Lambda and Java","datePublished":"2017-01-06T10:39:59+00:00","dateModified":"2023-05-19T11:12:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/"},"wordCount":1480,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Couchbase Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/","url":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/","name":"Is AWS Lambda PaaS | How is FaaS Different from PaaS","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2017-01-06T10:39:59+00:00","dateModified":"2023-05-19T11:12:27+00:00","description":"What is a serverless architecture? Find out how to make the AWS Lambda Function as a Service (FaaS) platform as opposed to Platform as a Service (PaaS).","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/serverless-faas-aws-lambda-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Serverless FaaS With AWS Lambda and Java"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/39d8caed0f536489b6aa6e8d31ee631f","name":"Arun Gupta, VP, Developer Advocacy, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8900a75409c646948fe0bd80f6240337","url":"https:\/\/secure.gravatar.com\/avatar\/f912e10b5f39748ee4f1a0b0da6f42747f0b3a94fe7acb511791468656f5e726?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f912e10b5f39748ee4f1a0b0da6f42747f0b3a94fe7acb511791468656f5e726?s=96&d=mm&r=g","caption":"Arun Gupta, VP, Developer Advocacy, Couchbase"},"description":"Arun Gupta is the vice president of developer advocacy at Couchbase. He has built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. He has deep expertise in leading cross-functional teams to develop and execute strategy, planning and execution of content, marketing campaigns, and programs. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team. Gupta has authored more than 2,000 blog posts on technology. He has extensive speaking experience in more than 40 countries on myriad topics and is a JavaOne Rock Star for three years in a row. Gupta also founded the Devoxx4Kids chapter in the US and continues to promote technology education among children. An author of several books on technology, an avid runner, a globe trotter, a Java Champion, a JUG leader, NetBeans Dream Team member, and a Docker Captain, he is easily accessible at @arungupta.","sameAs":["https:\/\/x.com\/arungupta"],"url":"https:\/\/www.couchbase.com\/blog\/author\/arun-gupta\/"}]}},"authors":[{"term_id":8933,"user_id":58,"is_guest":0,"slug":"arun-gupta","display_name":"Arun Gupta, VP, Developer Advocacy, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f912e10b5f39748ee4f1a0b0da6f42747f0b3a94fe7acb511791468656f5e726?s=96&d=mm&r=g","author_category":"","last_name":"Gupta","first_name":"Arun","job_title":"","user_url":"","description":"Arun Gupta is the vice president of developer advocacy at Couchbase. He has built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. He has deep expertise in leading cross-functional teams to develop and execute strategy, planning and execution of content, marketing campaigns, and programs. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team.\r\n\r\nGupta has authored more than 2,000 blog posts on technology. He has extensive speaking experience in more than 40 countries on myriad topics and is a JavaOne Rock Star for three years in a row. Gupta also founded the Devoxx4Kids chapter in the US and continues to promote technology education among children. An author of several books on technology, an avid runner, a globe trotter, a Java Champion, a JUG leader, NetBeans Dream Team member, and a Docker Captain, he is easily accessible at @arungupta."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/58"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2464"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2464\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2464"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}