floci-io/floci · error · AwsException
InvalidRequestException
InvalidRequestException
Error message
primary workGroup could not be created
What it means
Raised by the Athena emulator's CreateWorkGroup when the requested name equals 'primary'. AWS Athena pre-creates the 'primary' workgroup in every account/region, so attempting to create it again fails with InvalidRequestException / HTTP 400.
Source
Thrown at src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java:134
.orElseThrow(() -> new AwsException("InvalidRequestException",
"Query execution not found: " + id, 400));
}
public List<QueryExecution> listQueryExecutions() {
return queryStore.scan(k -> true);
}
public void stopQueryExecution(String id) {
QueryExecution execution = getQueryExecution(id);
execution.getStatus().setState(QueryExecutionState.CANCELLED);
execution.getStatus().setCompletionDateTime(Instant.now());
queryStore.put(id, execution);
}
public WorkGroup createWorkGroup(CreateWorkGroupRequest request, String region) {
validateWorkGroupName(request.getName());
if (DEFAULT_WORKGROUP.equals(request.getName())) {
throw new AwsException("InvalidRequestException",
DEFAULT_WORKGROUP + " workGroup could not be created", 400);
}
String key = workGroupKey(region, request.getName());
if (workGroupStore.get(key).isPresent()) {
throw new AwsException("InvalidRequestException", "WorkGroup already exists", 400);
}
WorkGroup workGroup = new WorkGroup();
workGroup.setName(request.getName());
workGroup.setDescription(request.getDescription());
workGroup.setState("ENABLED");
workGroup.setCreationTime(Instant.now());
workGroup.setTags(normalizeTags(request.getTags()));
workGroup.setConfiguration(normalizeWorkGroupConfiguration(request.getConfiguration()));
workGroupStore.put(key, workGroup);
return workGroup;
}
View on GitHub (pinned to 62ff490619)
Solutions
- Use the existing primary workgroup directly — no create call needed for it.
- If provisioning custom workgroups, pick a non-reserved name and check getWorkGroup() existence before createWorkGroup().
- Make bootstrap idempotent: catch/tolerate AlreadyExists-style outcomes instead of always creating.
Example fix
// before
athenaClient.createWorkGroup(r -> r.name("primary").configuration(c -> c.resultConfiguration(...)));
// after
try {
athenaClient.getWorkGroup(r -> r.workGroup("primary"));
} catch (Exception e) {
athenaClient.createWorkGroup(r -> r.name("my-wg").configuration(c -> c.resultConfiguration(...)));
} Defensive patterns
Strategy: validation
Validate before calling
static void requireCreatableWorkGroup(String name) {
if ("primary".equals(name))
throw new IllegalArgumentException("'primary' already exists; use it instead of creating it");
} Try / catch
try {
athenaClient.createWorkGroup(req);
} catch (InvalidRequestException e) {
if (e.getMessage().contains("could not be created") && "primary".equals(req.name())) {
return; // idempotent no-op: primary always exists
}
throw e;
} Prevention
- Default query execution to the existing primary workgroup instead of creating one.
- Make provisioning code check getWorkGroup() before createWorkGroup().
- Unit-test bootstrap against the reserved-name rule.
When it happens
Trigger: athenaClient.createWorkGroup(r -> r.name("primary")) or aws athena create-work-group --name primary. Happens in setup scripts that hardcode 'primary' as the default workgroup name.
Common situations: Applications defaulting to the primary workgroup and calling create unconditionally on startup; idempotent provisioning code that tries create-then-ignore-error instead of checking existence first.
Related errors
AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14).
Data as JSON: /api/errors/5fa4a4a34b81b1c7.
Report an issue: GitHub.