Provision log groups and streams for application tests, then retrieve or filter events into local JSON files. Task types live in io.github.gregwhitaker.awsemulator.aws.cloudwatchlogs.
Provision Before Tests
import io.github.gregwhitaker.awsemulator.aws.cloudwatchlogs.CreateLogGroupTask
import io.github.gregwhitaker.awsemulator.aws.cloudwatchlogs.CreateLogStreamTask
import io.github.gregwhitaker.awsemulator.aws.cloudwatchlogs.FilterLogEventsTask
plugins {
java
id("io.github.gregwhitaker.aws-emulator") version "0.3.0"
}
val logGroup = tasks.register<CreateLogGroupTask>("createTestLogGroup") {
logGroupName.set("/application/tests")
}
val logStream = tasks.register<CreateLogStreamTask>("createTestLogStream") {
dependsOn(logGroup)
logGroupName.set("/application/tests")
logStreamName.set("application")
}
val tests = tasks.named<Test>("test") { dependsOn(logStream) }
awsEmulator { useWith(tests) }
val filtered = tasks.register<FilterLogEventsTask>("filterTestLogs") {
dependsOn(tests)
logGroupName.set("/application/tests")
filterPattern.set("ready")
minimumEvents.set(1)
outputFile.set(layout.buildDirectory.file("logs/filtered.json"))
}
tasks.register("verifyLogs") { dependsOn(filtered) }
Have the tests write an application log event containing ready to the configured group and stream. Run ./gradlew verifyLogs to provision the stream, run the tests, and retrieve the matching events before managed cleanup.
Task Properties
-
CreateLogGroupTask/DeleteLogGroupTask:logGroupName. -
CreateLogStreamTask/DeleteLogStreamTask:logGroupName,logStreamName. Create the group first usingdependsOn. -
ListLogGroupsTask: lists group names. -
GetLogEventsTask:logGroupName,logStreamName,outputFile, optionalstartTimein epoch milliseconds,maxEvents(default 10000). -
FilterLogEventsTask:logGroupName,outputFile,filterPattern(default empty), optionalstartTime,maxEvents,minimumEvents(default 0),waitTimeoutSeconds(default 30).
Reading And Filtering Events
Read tasks follow pagination and write JSON arrays without printing message bodies. GetLogEventsTask terminates when the forward token stops advancing. FilterLogEventsTask optionally polls until at least minimumEvents match; each poll replaces its snapshot rather than appending duplicates. Exceeding maxEvents fails rather than silently truncating. Raise the limit (maximum 1000000) or narrow the query. SDK calls retain the shared apiCallTimeoutSeconds deadline, including when a polling deadline expires during a call.
Development Commands
Predefined commands: listLogGroups, deleteLogGroup --logGroupName=…, and deleteLogStream --logGroupName=… --logStreamName=…. Log retention policies, subscriptions, Logs Insights, metrics, and alarms are outside this initial scope.
When deleting a stream and its group in the same build, declare tasks.named("deleteLogGroup") { mustRunAfter("deleteLogStream") }. Configuration-cache execution can run independent tasks concurrently. The runnable example configures this ordering.
./gradlew listLogGroups
./gradlew deleteLogStream --logGroupName=/application/tests --logStreamName=application
./gradlew deleteLogGroup --logGroupName=/application/tests
Runtime Selection
Custom resource tasks inherit awsEmulator.defaultMode, initially MANAGED. Make the consuming test or application task depend on provisioning and opt that consumer in with awsEmulator.useWith(…). Provisioning and consumers must select the same runtime name and mode; see resource task defaults to configure a shared development default.
Every task accepts runtimeName (default default), mode, and apiCallTimeoutSeconds (default 30, positive). Predefined inspection and deletion commands default to DEVELOPMENT; select another mode with --mode=MANAGED or another declared runtime with --runtime <name>. For persistent setup, see development resource tasks.
Resource tasks always execute against live emulator state and do not use the build cache. Configuration-cache reuse is supported. Applying the plugin and listing tasks do not start Docker. Task input values may be stored in Gradle’s configuration cache; fixtures should contain local test values.
Runnable Example
./gradlew -p examples/services verifyServices --configuration-cache
The example writes an application log event through AWS SDK for Java v2, then retrieves and filters the events into JSON files. Run the command twice to check configuration-cache reuse against a fresh managed emulator. -PfailExample=true deliberately fails the application test to demonstrate cleanup. See the runnable example for its complete setup and persistent development commands.
Verified Scope
The examples exercise these workflows against the pinned AWS Emulator 1.0.385, using AWS SDK for Java v2 2.39.6. They establish the behavior used by these tasks, not complete AWS service equivalence. AWS Emulator fidelity varies by operation and release.