floci-io/floci · error · AwsException

ResourceAlreadyExistsException

ResourceAlreadyExistsException

Error message

Project already exists:  " + name

What it means

Thrown by CodeBuildService.createProject when a project with the same name already exists in the region's project store. Checked before any validation of the payload. Maps to AWS ResourceAlreadyExistsException, though Floci returns it with HTTP 400.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java:134

    // ---- Projects ----

    public Project createProject(String region, String account,
                                 String name, String description,
                                 ProjectSource source, List<ProjectSource> secondarySources,
                                 String sourceVersion,
                                 ProjectArtifacts artifacts, List<ProjectArtifacts> secondaryArtifacts,
                                 ProjectEnvironment environment,
                                 String serviceRole,
                                 Integer timeoutInMinutes, Integer queuedTimeoutInMinutes,
                                 String encryptionKey,
                                 List<Map<String, String>> tags,
                                 Map<String, Object> logsConfig,
                                 Map<String, Object> vpcConfig,
                                 Integer concurrentBuildLimit) {
        Map<String, Project> store = projectsFor(region);
        if (store.containsKey(name)) {
            throw new AwsException("ResourceAlreadyExistsException",
                    "Project already exists: " + name, 400);
        }
        validateProjectName(name);
        if (source == null || source.getType() == null) {
            throw new AwsException("InvalidInputException", "source.type is required", 400);
        }
        if (environment == null) {
            throw new AwsException("InvalidInputException", "environment is required", 400);
        }
        if (serviceRole == null || serviceRole.isBlank()) {
            throw new AwsException("InvalidInputException", "serviceRole is required", 400);
        }
        if (artifacts == null || artifacts.getType() == null) {
            throw new AwsException("InvalidInputException", "artifacts.type is required", 400);
        }

        double now = Instant.now().toEpochMilli() / 1000.0;
        Project project = new Project();

View on GitHub (pinned to 62ff490619)

Solutions

  1. Delete the existing project first (DeleteProject) if you intend to recreate it
  2. Use UpdateProject for subsequent applies of changed configuration
  3. Make bootstrap scripts idempotent: check BatchGetProjects/list-projects before CreateProject
  4. Use unique names per environment/job to avoid collisions

Example fix

# before
aws --endpoint-url http://localhost:4566 codebuild create-project --name demo ...
# -> ResourceAlreadyExistsException on re-run

# after
name=demo-$(date +%s)  # or:
aws --endpoint-url http://localhost:4566 codebuild delete-project --name demo || true
aws --endpoint-url http://localhost:4566 codebuild create-project --name demo ...
Defensive patterns

Strategy: validation

Validate before calling

// Java, SDK v2 - existence check before create
boolean exists = codebuild.batchGetProjects(r -> r.names(name)).projects().stream()
        .anyMatch(p -> p.name().equals(name));
if (exists) throw new IllegalStateException("Project " + name + " already exists - update instead");

Try / catch

catch (ResourceAlreadyExistsException e) {
    // decide policy: adopt existing project (update) or delete+recreate; never blind-retry create
    if (adoptExisting) codebuild.updateProject(toUpdate(name, cfg));
    else { codebuild.deleteProject(r -> r.name(name)); codebuild.createProject(cfg); }
}

Prevention

When it happens

Trigger: Running CreateProject twice with the same name; re-running an infrastructure bootstrap script (CDK/Terraform apply) that calls CreateProject instead of UpdateProject on subsequent runs; IaC templates that hardcode a shared project name across environments in the same Floci region.

Common situations: Idempotent deployment scripts that assume create-or-update semantics; concurrent CI jobs creating the same named project; test suites that do not clean up projects between runs.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/7c11aef6b2c58fae. Report an issue: GitHub.