in DeliveryApi/cdk/src/main/java/com/ilmlf/delivery/api/ApiStack.java [463:526]
public ApiFunction defaultLambdaRdsProxy(String functionName, ApiStackProps props, Role role)
throws IOException {
/*
* Command for building Java handler inside a container
*/
List<String> apiHandlersPackagingInstructions =
Arrays.asList(
"/bin/sh",
"-c",
"./gradlew build "
+ "&& ls /asset-output/"
+ "&& cp build/distributions/lambda.zip /asset-output/");
BundlingOptions builderOptions =
BundlingOptions.builder()
// CDK will try to build resource locally with the `tryBundle()` first
.local((s, bundlingOptions) -> this.tryBundle(s))
// If `tryBundle()` fails (return false), it will use the instructions in `command`
// to build inside Docker with the given image.
.command(apiHandlersPackagingInstructions)
.image(Runtime.JAVA_11.getBundlingImage())
.user("root")
.outputType(ARCHIVED)
.build();
ApiFunction function =
new ApiFunction(
this,
functionName,
FunctionProps.builder()
.environment(
Map.of(
"DB_ENDPOINT",
functionName.equals("PopulateFarmDb")
? props.getDbEndpoint()
: props.getDbProxyEndpoint(),
"DB_PORT", props.getDbPort().toString(),
"DB_REGION", props.getDbRegion(),
"DB_USER", props.getDbUser(),
"DB_ADMIN_SECRET", props.getDbAdminSecretName(),
"DB_USER_SECRET", props.getDbUserSecretName(),
"CORS_ALLOW_ORIGIN_HEADER", "*"))
.runtime(Runtime.JAVA_11)
.code(
Code.fromAsset(
"../ApiHandlers",
AssetOptions.builder()
.assetHashType(AssetHashType.CUSTOM)
.assetHash(Hashing.hashDirectory("../ApiHandlers/src", false))
.bundling(builderOptions)
.build()))
.timeout(Duration.seconds(60))
.memorySize(2048)
.handler("com.ilmlf.delivery.api.handlers." + functionName)
.vpc(this.dbVpc)
.securityGroups(List.of(this.dbSg))
.functionName(functionName)
.role(role)
.build());
return function;
}