GH-530, GH-630 Improvements to AWS Custom Runtime
This commit provides initial set of improvements to executing functions in AWS Custom Runtime - Consistent invocation model for functional as well as @Bean configuration models via new CustomRuntimeEventLoop as well as AWSLambdaUtils - Clean up classpath to decrease the size of the JAR/ZIP file - Configuration simplification which no longer requires enabling of function exporter It also allows user to define functions that rely on AWS types such as APIGatewayProxyRequestEvent The existing invocation model remains in tact for the time being. Both invocation models are mutually exclusing in theit setup to avoid potential conflict. Resolves #538 Resolves #630
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 https://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>zip</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<baseDirectory></baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<excludes>
|
||||
<exclude>bootstrap</exclude>
|
||||
</excludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<fileMode>0775</fileMode>
|
||||
<includes>
|
||||
<include>bootstrap</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/lib</outputDirectory>
|
||||
<unpack>false</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.example;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
|
||||
@SpringBootApplication
|
||||
public class LambdaApplication {
|
||||
|
||||
private static Log logger = LogFactory.getLog(LambdaApplication.class);
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return value -> {
|
||||
logger.info("UPPERCASING: " + value);
|
||||
return value.toUpperCase();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<APIGatewayProxyRequestEvent, String> extractPayloadFromGatewayEvent() {
|
||||
return value -> {
|
||||
logger.info("ECHO Payload from Gateway Event: " + value.getBody());
|
||||
return value.getBody();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Message<String>, Message<String>> echoMessage() {
|
||||
return value -> {
|
||||
logger.info("ECHO MESSAGE: " + value);
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> reverse() {
|
||||
return value -> {
|
||||
logger.info("REVERSING: " + value);
|
||||
return new StringBuilder(value).reverse().toString();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=====> ENVIRONMENT: " + System.getenv("AWS_LAMBDA_RUNTIME_API"));
|
||||
//FunctionalSpringApplication.run(LambdaApplication.class, args);
|
||||
logger.info("==> Starting: LambdaApplication");
|
||||
if (!ObjectUtils.isEmpty(args)) {
|
||||
logger.info("==> args: " + Arrays.asList(args));
|
||||
}
|
||||
SpringApplication.run(LambdaApplication.class, args);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void initialize(GenericApplicationContext context) {
|
||||
// context.registerBean("uppercase", FunctionRegistration.class,
|
||||
// () -> new FunctionRegistration<>(uppercase()).type(
|
||||
// FunctionType.from(String.class).to(String.class)));
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
spring.main.web-application-type=none
|
||||
logging.level.org.springframework.cloud=DEBUG
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd ${LAMBDA_TASK_ROOT:-.}
|
||||
|
||||
java -Dspring.main.web-application-type=none -Dspring.jmx.enabled=false \
|
||||
-noverify -XX:TieredStopAtLevel=1 -Xss256K -XX:MaxMetaspaceSize=128M \
|
||||
-Djava.security.egd=file:/dev/./urandom \
|
||||
-cp .:`echo lib/*.jar | tr ' ' :` com.example.LambdaApplication
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
while true
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
Reference in New Issue
Block a user