Files
spring-cloud-function/spring-cloud-function-samples/function-sample-aws/src/main/java/example/FunctionConfiguration.java
2021-07-30 18:32:52 +02:00

45 lines
1.2 KiB
Java

package example;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPResponse;
@SpringBootApplication
public class FunctionConfiguration {
/*
* You need this main method or explicit <start-class>example.FunctionConfiguration</start-class>
* in the POM to ensure boot plug-in makes the correct entry
*/
public static void main(String[] args) {
SpringApplication.run(FunctionConfiguration.class, args);
}
@Bean
public Function<String, String> uppercase() {
return value -> {
if (value.equals("exception")) {
throw new RuntimeException("Intentional exception which should result in HTTP 417");
}
else {
return value.toUpperCase();
}
};
}
@Bean
public Function<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse> uppercaseApiGateway() {
return value -> {
APIGatewayV2HTTPResponse response = new APIGatewayV2HTTPResponse();
response.setStatusCode(404);
response.setBody("Resource not found");
return response;
};
}
}