I am using CDK bundling on Docker to build a Java package that uses DynamoDB local in its tests.
this.function = new lambda.Function(this, "Function", {
runtime: lambda.Runtime.JAVA_21,
code: lambda.Code.fromAsset(`../assets-java/${props.serviceName}`, {
bundling: {
command: [
"/bin/sh",
"-c",
`mvn clean install && cp /asset-input/target/${props.serviceName}-1.0.jar /asset-output/`,
],
image: lambda.Runtime.JAVA_21.bundlingImage,
bundlingFileAccess: cdk.BundlingFileAccess.VOLUME_COPY,
user: "root",
outputType: cdk.BundlingOutput.ARCHIVED,
network: "java-build-local",
volumes: [
{
hostPath: process.env["HOME"] + "/.m2/",
containerPath: "/root/.m2/"
},
{
hostPath: "/var/run/docker.sock",
containerPath: "/var/run/docker.sock"
}
],
}
}),
handler: props.handler,
logRetention: RetentionDays.THREE_MONTHS,
timeout: Duration.minutes(5),
environment: {
...props.env,
"JAVA_TOOL_OPTIONS": "-Dlog4j.configurationFile=log4j2.xml"
}
})
I’ve tried running the dynamodb-local container from from the maven build via docker
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.0</version>
<executions>
<execution>
<id>start-docker-container</id>
<phase>generate-test-resources</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-docker-container</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<images>
<image>
<name>amazon/dynamodb-local</name>
<run>
<ports>
<port>8123:8000</port>
</ports>
<network>
<name>java-build-local</name>
<alias>dynamodb-local</alias>
</network>
</run>
</image>
</images>
</configuration>
</plugin>
And this is telling me that the network is not found
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.38.0:start (start-docker-container) on project conversation-service: I/O Error: Unable to start container id [ad35df5ed9e1] : {"message":"network java-build-local not found"} (Not Found: 404) -> [Help 1]
I’d really rather not have to manually create the network ahead of time, so I’m hoping there’s a better way to get the dynamodb/local container running alongside the actual bundling container.