in infrastructure/src/main/java/com/myorg/InfrastructureStack.java [36:120]
public InfrastructureStack(final Construct parent, final String id, final StackProps props) {
super(parent, id, props);
List<String> functionOnePackagingInstructions = Arrays.asList(
"/bin/sh",
"-c",
"cd FunctionOne " +
"&& mvn clean install " +
"&& cp /asset-input/FunctionOne/target/functionone.jar /asset-output/"
);
List<String> functionTwoPackagingInstructions = Arrays.asList(
"/bin/sh",
"-c",
"cd FunctionTwo " +
"&& mvn clean install " +
"&& cp /asset-input/FunctionTwo/target/functiontwo.jar /asset-output/"
);
BundlingOptions.Builder builderOptions = BundlingOptions.builder()
.command(functionOnePackagingInstructions)
.image(Runtime.JAVA_11.getBundlingImage())
.volumes(singletonList(
// Mount local .m2 repo to avoid download all the dependencies again inside the container
DockerVolume.builder()
.hostPath(System.getProperty("user.home") + "/.m2/")
.containerPath("/root/.m2/")
.build()
))
.user("root")
.outputType(ARCHIVED);
Function functionOne = new Function(this, "FunctionOne", FunctionProps.builder()
.runtime(Runtime.JAVA_11)
.code(Code.fromAsset("../software/", AssetOptions.builder()
.bundling(builderOptions
.command(functionOnePackagingInstructions)
.build())
.build()))
.handler("helloworld.App")
.memorySize(1024)
.timeout(Duration.seconds(10))
.logRetention(RetentionDays.ONE_WEEK)
.build());
Function functionTwo = new Function(this, "FunctionTwo", FunctionProps.builder()
.runtime(Runtime.JAVA_11)
.code(Code.fromAsset("../software/", AssetOptions.builder()
.bundling(builderOptions
.command(functionTwoPackagingInstructions)
.build())
.build()))
.handler("helloworld.App")
.memorySize(1024)
.timeout(Duration.seconds(10))
.logRetention(RetentionDays.ONE_WEEK)
.build());
HttpApi httpApi = new HttpApi(this, "sample-api", HttpApiProps.builder()
.apiName("sample-api")
.build());
httpApi.addRoutes(AddRoutesOptions.builder()
.path("/one")
.methods(singletonList(HttpMethod.GET))
.integration(new LambdaProxyIntegration(LambdaProxyIntegrationProps.builder()
.handler(functionOne)
.payloadFormatVersion(PayloadFormatVersion.VERSION_2_0)
.build()))
.build());
httpApi.addRoutes(AddRoutesOptions.builder()
.path("/two")
.methods(singletonList(HttpMethod.GET))
.integration(new LambdaProxyIntegration(LambdaProxyIntegrationProps.builder()
.handler(functionTwo)
.payloadFormatVersion(PayloadFormatVersion.VERSION_2_0)
.build()))
.build());
new CfnOutput(this, "HttApi", CfnOutputProps.builder()
.description("Url for Http Api")
.value(httpApi.getApiEndpoint())
.build());
}