floci-io/floci · error · AwsException

ResourceNotFoundException

ResourceNotFoundException

Error message

Environment not found in this application

What it means

Thrown by AppConfigService.getEnvironment() when an environment with the given envId exists in the store but belongs to a different application than the appId supplied. The first lookup ('Environment not found') covers a nonexistent envId; this second check covers an ID/ownership mismatch and deliberately returns the same ResourceNotFoundException (404) with a distinguishing message, mirroring AWS's behavior of not leaking cross-application resource existence.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java:77

    }

    // ──────────────────────────── Environment ────────────────────────────

    public Environment createEnvironment(String appId, Map<String, Object> request) {
        getApplication(appId);
        Environment env = new Environment();
        env.setId(shortId(7));
        env.setApplicationId(appId);
        env.setName((String) request.get("Name"));
        env.setDescription((String) request.get("Description"));
        env.setState("READY");
        environmentStore.put(env.getId(), env);
        return env;
    }

    public Environment getEnvironment(String appId, String envId) {
        Environment env = environmentStore.get(envId).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Environment not found", 404));
        if (!env.getApplicationId().equals(appId)) throw new AwsException("ResourceNotFoundException", "Environment not found in this application", 404);
        return env;
    }

    public List<Environment> listEnvironments(String appId) {
        return environmentStore.scan(k -> true).stream()
                .filter(e -> e.getApplicationId().equals(appId))
                .toList();
    }

    // ──────────────────────────── Configuration Profile ────────────────────────────

    public ConfigurationProfile createConfigurationProfile(String appId, Map<String, Object> request) {
        getApplication(appId);
        ConfigurationProfile profile = new ConfigurationProfile();
        profile.setId(shortId(7));
        profile.setApplicationId(appId);
        profile.setName((String) request.get("Name"));
        profile.setDescription((String) request.get("Description"));

View on GitHub (pinned to 62ff490619)

Solutions

  1. List environments under the application you think owns it (ListEnvironments with that appId) and use the envId it returns.
  2. Cross-check the appId: ListApplications and confirm the id in your command matches the application that created the environment.
  3. If the application was recreated, re-create the environment under the new app id and update references.
  4. Keep app/env id pairs together in one config block instead of assembling them from independent variables.

Example fix

# before
aws appconfig get-environment \
  --application-id wrongapp1 --environment-id e123abc

# after (find the true owner first)
aws appconfig list-environments --application-id realapp2
aws appconfig get-environment \
  --application-id realapp2 --environment-id e123abc
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm ownership before fetching
boolean owned = appConfig.listEnvironments(appId).stream()
    .anyMatch(e -> e.getId().equals(envId));
if (!owned) {
    throw new IllegalArgumentException("env " + envId + " not under application " + appId);
}
Environment env = appConfig.getEnvironment(appId, envId);

Try / catch

catch (AwsException e) {
    if ("ResourceNotFoundException".equals(e.getCode())) {
        if (e.getMessage().contains("in this application")) {
            // ownership mismatch: resolve the true owner via listEnvironments on other apps
            log.warn("{} belongs to another application; listing apps to relocate", envId);
        }
        // both variants are terminal 404s — never retry
        return Optional.empty();
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling GetEnvironmentConfiguration / GetEnvironment with the right envId but the wrong ApplicationId — e.g. copy-pasting an app id from another profile, or a test fixture that created the environment under app A and queries it under app B. Environment ids are shortId(7) values unique across the store, so a hit with a different owner is always an ownership mismatch, not an id collision.

Common situations: Scripts that hardcode application ids and drift after recreating the application. Configuration files where the app identifier was refreshed but the environment references were not. Multi-application tenants where the same logical env name exists under two apps and the wrong app's id is used.

Related errors


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