cloud.localstack.LambdaExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of localstack-utils Show documentation
Show all versions of localstack-utils Show documentation
Java utilities for the LocalStack platform.
package cloud.localstack;
import cloud.localstack.awssdkv1.lambda.DDBEventParser;
import cloud.localstack.awssdkv1.lambda.KinesisEventParser;
import cloud.localstack.awssdkv1.lambda.S3EventParser;
import cloud.localstack.lambda_handler.HandlerNameParseResult;
import cloud.localstack.lambda_handler.MultipleMatchingHandlersException;
import cloud.localstack.lambda_handler.NoMatchingHandlerException;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.amazonaws.services.lambda.runtime.events.SNSEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.util.StringInputStream;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Simple implementation of a Java Lambda function executor.
*
* @author Waldemar Hummer
*/
@SuppressWarnings("restriction")
public class LambdaExecutor {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
if (args.length != 1 && args.length != 2) {
System.err.println("Usage: java " + LambdaExecutor.class.getSimpleName() +
" [] ");
System.exit(1);
}
String fileContent = args.length == 1 ? readFile(args[0]) : readFile(args[1]);
ObjectMapper reader = new ObjectMapper();
reader.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
reader.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Map map = reader.readerFor(Map.class).readValue(fileContent);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy