Skip to content

Instantly share code, notes, and snippets.

View mikebroberts's full-sized avatar

Mike Roberts mikebroberts

View GitHub Profile
package io.symphonia;
public class PojoLambda {
public PojoResponse handlerPojo(PojoInput input) {
return new PojoResponse("Input was " + input.c);
}
public static class PojoInput {
public String c;
}
@mikebroberts
mikebroberts / make-java-api.sh
Created April 3, 2017 15:27
Zero-to-production Java / Lambda / API Gateway script
#!/bin/bash
# Creates a Lambda and API Gateway proxying any verb on any path to lambda
#
# PREREQUISITES
#
# You must have the following installed locally: Java 8, mvn, AWS CLI
# Your AWS CLI must be configured for a user that has the necessary privileges
# You must have a basic role 'lambda_basic_execution' defined - this is what is created
# the first time you create a Lambda function in the web console
public String handler(String s) {
return "Hello, " + s;
}
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
package io.symphonia;
import com.amazonaws.services.lambda.runtime.Context;
import java.util.HashMap;
import java.util.Map;
public class ContextLambda {
public Map<String,Object> handler (Object input, Context context) {
Map<String, Object> toReturn = new HashMap<>();
package io.symphonia;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamLambda {
public void handlerStream(InputStream inputStream, OutputStream outputStream) throws IOException {
int letter;
while((letter = inputStream.read()) != -1)
public Object handleRequest(S3Event input) {
// …
}
package io.symphonia;
public class PojoLambda {
public PojoResponse handlerPojo(PojoInput input) {
return new PojoResponse("Input was " + input.getA());
}
public static class PojoInput {
private String a;
package io.symphonia;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ListMapLambda {
public List<Integer> handlerList(List<Integer> input) {
List<Integer> newList = new ArrayList<>();
package io.symphonia;
public class StringIntegerBooleanLambda {
public String handlerString(String s) {
return "Hello, " + s;
}
public int handlerInt(int input) {
return 100 + input;
}