Lab 3
Lab 3
Lab 3
AWS Lambda
AWS Lambda is an event-driven, serverless
computing platform provided by Amazon as a
part of Amazon Web Services. It is a computing
service that runs code in response to events and
automatically manages the computing resources
required by that code. It was introduced in
November 2014.
AWS Lambda
• lets you run code without provisioning or
managing servers.
• is an event-driven
AWS Toolkit for Eclipse 2.0
• Go to Eclipse EE -> Help - > Eclipse Marketplace
AWS Toolkit for Eclipse 2.0
• Type aws and chose AWS Toolkit for Eclipse 2.0, then
click on Install button
AWS Toolkit for Eclipse 2.0
• Click on Confirm button
AWS Toolkit for Eclipse 2.0
• Click on I accept the terms… and then click on Finish.
• After Eclipse Restart add your logging aws credentials
AWS Lambda Java Project
• Chose New AWS Lambda Java Project…
AWS Lambda Java Project
• Fill the fields like this:
AWS Lambda Java Project
• Fill the fields like this:
AWS Lambda Java Project
• In the pom.xml we can see the dependencies
to amazon web services were added.
AWS Lambda Java Project
• We will create an application that generate a
random number
• Edit LambdaFunctionHandler.java like this:
package com.amazonaws.lambda.demo;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import java.util.Random;
@Override
public String handleRequest(Object input, Context context) {
context.getLogger().log("Input: " + input);
}
AWS Lambda Java Project
• Comment this line of code
package com.amazonaws.lambda.demo;
import java.io.IOException;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.amazonaws.services.lambda.runtime.Context;
/**
* A simple test harness for locally invoking your Lambda function handler.
*/
public class LambdaFunctionHandlerTest {
@BeforeClass
public static void createInput() throws IOException {
// TODO: set up your sample input object here.
input = null;
}
return ctx;
}
@Test
public void testLambdaFunctionHandler() {
LambdaFunctionHandler handler = new LambdaFunctionHandler();
Context ctx = createContext();
com.amazonaws.lambda.demo.LambdaFunctionHandler::handleRequest
AWS Lambda
• Click on “Configure a new test events”
AWS Lambda
• Add a test event, delete de content of the Json
file and click on Save.
AWS Lambda
• Click on Test button and you should see
something like this.
AWS Lambda API Gateway
• Click on Add trigger button.
AWS Lambda API Gateway
• Chose API Gateway and configure like this:
AWS Lambda API Gateway
• You can test the API endpoint now. Click on
the link and refresh the page few times.
AWS API Gateway
There is another way to create an API endpoint.
This methods will be presented in the following
slides.
AWS API Gateway
1. go to https://www.awseducate.com/signin/SiteLogin and
enter your email and password from the amazon’s email.
2. Click on AWS Account and then on AWS Educate Starter
Account
AWS API Gateway
3. click on AWS Console
com.amazonaws.lambda.demo. S3LambdaHandler::handleRequest
Lambda - S3 trigger
• Click on Add trigger
Lambda - S3 trigger
• Chose S3
Lambda - S3 trigger
• Select your bucket and click on Add button
Lambda - S3 trigger
• Select Permission and click on Edit
Lambda - S3 trigger
• Click on Create a new role and add S3 policy
Lambda - S3 trigger
• Go to your s3 bucket and enable logging.
Lambda - S3 trigger
• After you upload a file into S3 go to aws
console and then go to cloud watch
Lambda - S3 trigger
• Click on Logs, then click on Let’s get started
Lambda - S3 trigger
• After you click on your lambda function you
should see something like this: