{"record":{"id":"1d78840ff9a6b479","repo":"floci-io/floci","slug":"alreadyexists","errorCode":"AlreadyExists","errorMessage":"Launch configuration '{name}' already exists.","messagePattern":"Launch configuration '(.+?)' already exists\\.","errorType":"exception","errorClass":"AwsException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java","lineNumber":80,"sourceCode":"        this.activities = storageBacked(\"autoscaling-activities.json\", new TypeReference<Map<String, ScalingActivity>>() {});\n        this.instanceRefreshes = storageBacked(\"autoscaling-instance-refreshes.json\", new TypeReference<Map<String, InstanceRefresh>>() {});\n    }\n\n    private <V> Map<String, V> storageBacked(String fileName, TypeReference<Map<String, V>> typeReference)\n    {\n        return new StorageBackedMap<>(storageFactory.create(\"autoscaling\", fileName, typeReference));\n    }\n\n    // ── Launch Configurations ──────────────────────────────────────────────────\n\n    public LaunchConfiguration createLaunchConfiguration(String region, String name, String instanceId,\n                                                          String imageId, String instanceType, String keyName,\n                                                          List<String> securityGroups, String userData,\n                                                          String iamInstanceProfile,\n                                                          Boolean associatePublicIpAddress) {\n        String key = lcKey(region, name);\n        if (launchConfigs.containsKey(key)) {\n            throw new AwsException(\"AlreadyExists\",\n                    \"Launch configuration '\" + name + \"' already exists.\", 400);\n        }\n        if (isBlank(instanceId) && (isBlank(imageId) || isBlank(instanceType))) {\n            throw new AwsException(\"ValidationError\", INVALID_LAUNCH_CONFIGURATION_PARAMETERS_MESSAGE, 400);\n        }\n        if (notBlank(instanceId) && ec2Service != null) {\n            List<Instance> sourceInstances = ec2Service.describeInstances(region, List.of(instanceId), Map.of())\n                    .stream()\n                    .flatMap(reservation -> reservation.getInstances().stream())\n                    .collect(Collectors.toList());\n            if (!sourceInstances.isEmpty()) {\n                Instance source = sourceInstances.getFirst();\n                if (isBlank(imageId)) {\n                    imageId = source.getImageId();\n                }\n                if (isBlank(instanceType)) {\n                    instanceType = source.getInstanceType();\n                }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java#L62-L98","documentation":"Thrown by the Auto Scaling emulator when CreateLaunchConfiguration uses a name that already exists in the given region. AWS Auto Scaling launch configuration names are region-unique; the real service returns AlreadyExists (HTTP 400 in this emulator) on duplicates.","triggerScenarios":"Calling createLaunchConfiguration twice with the same name in the same region; re-running a provisioning script; integration tests against persistent emulator storage where launch configs survived the previous run.","commonSituations":"Non-idempotent bootstrap scripts; emulator persistence mode keeping state across restarts; parallel CI jobs sharing one emulator instance.","solutions":["Check describeLaunchConfigurations for the name first and skip creation if present (or delete-then-create for updates).","Use unique names per run (timestamp/UUID suffix) in tests.","Remember launch configurations are immutable in AWS — to change one, create a new name and update the ASG.","Clear persistent emulator storage between test sessions if fixtures are assumed fresh."],"exampleFix":"# before\naws autoscaling create-launch-configuration \\\n  --launch-configuration-name web --image-id ami-123 --instance-type t3.micro\n\n# after\naws autoscaling delete-launch-configuration --launch-configuration-name web || true\naws autoscaling create-launch-configuration \\\n  --launch-configuration-name web --image-id ami-123 --instance-type t3.micro","handlingStrategy":"validation","validationCode":"boolean exists = autoScalingClient.describeLaunchConfigurations(\n        r -> r.launchConfigurationNames(name)).launchConfigurations().stream()\n        .anyMatch(lc -> name.equals(lc.launchConfigurationName()));\nif (!exists) autoScalingClient.createLaunchConfiguration(req);","typeGuard":null,"tryCatchPattern":"try {\n    autoScalingClient.createLaunchConfiguration(req);\n} catch (AutoScalingException e) {\n    if (\"AlreadyExists\".equals(e.awsErrorDetails().errorCode())) return; // idempotent\n    throw e;\n}","preventionTips":["Treat launch configuration names as immutable versions (app-v1, app-v2) instead of reusing one name.","Run describe-before-create in provisioning scripts.","Delete fixtures in test teardown; remember AWS launch configs cannot be updated, only replaced."],"tags":["autoscaling","launch-configuration","duplicate","stateful-emulator","create"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}