floci-io/floci · error · AwsException

AlreadyExistsException

AlreadyExistsException

Error message

Backup vault already exists: {vaultName}

What it means

Thrown by createBackupVault when a vault with the same name already exists in the region (vault keys are region + name). AWS Backup vault names are unique per region and per account, so re-creating an existing name fails with AlreadyExistsException (HTTP 400).

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/backup/BackupService.java:71

        this.jobStore       = storageFactory.create("backup", "backup-jobs.json",       new TypeReference<>() {});
        this.recoveryStore  = storageFactory.create("backup", "backup-recovery-points.json", new TypeReference<>() {});
        this.regionResolver = regionResolver;
        this.jobCompletionDelaySeconds = config.services().backup().jobCompletionDelaySeconds();
    }

    @PreDestroy
    void shutdown() {
        scheduler.shutdownNow();
    }

    // ── Vault ──────────────────────────────────────────────────────────────────

    public BackupVault createBackupVault(String vaultName, String encryptionKeyArn,
                                         String creatorRequestId, Map<String, String> tags,
                                         String region) {
        String key = vaultKey(region, vaultName);
        if (vaultStore.get(key).isPresent()) {
            throw new AwsException("AlreadyExistsException", "Backup vault already exists: " + vaultName, 400);
        }
        BackupVault vault = new BackupVault();
        vault.setBackupVaultName(vaultName);
        vault.setBackupVaultArn(regionResolver.buildArn("backup", region, "backup-vault:" + vaultName));
        vault.setEncryptionKeyArn(encryptionKeyArn);
        vault.setCreationDate(Instant.now().getEpochSecond());
        vault.setCreatorRequestId(creatorRequestId);
        vault.setNumberOfRecoveryPoints(0);
        vault.setTags(tags);
        vaultStore.put(key, vault);
        LOG.infov("Created backup vault {0} in {1}", vaultName, region);
        return vault;
    }

    public BackupVault describeBackupVault(String vaultName, String region) {
        return vaultStore.get(vaultKey(region, vaultName))
                .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Backup vault not found: " + vaultName, 404));
    }

View on GitHub (pinned to 62ff490619)

Solutions

  1. Call DescribeBackupVault / ListBackupVaults first and reuse the existing vault if present
  2. Or catch AlreadyExistsException and treat it as success when the existing vault matches your intent
  3. Use unique vault names per test run when isolation matters

Example fix

// before
backup.createBackupVault(CreateBackupVaultRequest.builder()
    .backupVaultName("audit-vault").build());

// after
try {
    backup.createBackupVault(CreateBackupVaultRequest.builder()
        .backupVaultName("audit-vault").build());
} catch (AlreadyExistsException e) {
    // vault already present — reuse it
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean exists = backup.listBackupVaults(ListBackupVaultsRequest.builder().build())
    .backupVaultList().stream()
    .anyMatch(v -> vaultName.equals(v.backupVaultName()));
if (!exists) { backup.createBackupVault(...); }

Try / catch

catch (AlreadyExistsException e) { /* idempotent create — fetch and reuse the existing vault */ }

Prevention

When it happens

Trigger: Calling CreateBackupVault twice with the same BackupVaultName in the same region; re-running an init script that creates the default vault without checking first.

Common situations: Idempotent-looking setup scripts that don't check existence; repeated test fixtures between emulator restarts when persistence retains state; assuming a CreatorRequestId deduplicates like it does in some AWS APIs — here the name alone collides.

Related errors


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