floci-io/floci · error · AwsException
NameAlreadyExistsException
NameAlreadyExistsException
Error message
StackSet already exists: ${name} What it means
NameAlreadyExistsException (HTTP 409) from createStackSet when a StackSet with the same name is already registered in the emulator's stackset storage. StackSet names are unique per account.
Source
Thrown at src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java:64
public StackSetService(CloudFormationService cfnService, StorageFactory storageFactory) {
this.cfnService = cfnService;
this.stackSets = storageFactory.create("cloudformation", "cloudformation-stacksets.json",
new TypeReference<Map<String, StackSet>>() {});
this.instances = storageFactory.create("cloudformation", "cloudformation-stackset-instances.json",
new TypeReference<Map<String, StackInstance>>() {});
this.operations = storageFactory.create("cloudformation", "cloudformation-stackset-operations.json",
new TypeReference<Map<String, StackSetOperation>>() {});
}
// ── StackSet lifecycle ─────────────────────────────────────────────────────
public StackSet createStackSet(String name, String templateBody, Map<String, String> parameters,
List<String> capabilities, Map<String, String> tags, String description) {
if (name == null || name.isBlank()) {
throw new AwsException("ValidationError", "StackSetName must not be empty", 400);
}
if (stackSets.get(name).isPresent()) {
throw new AwsException("NameAlreadyExistsException",
"StackSet already exists: " + name, 409);
}
// AWS rejects CreateStackSet with no template; the handler resolves TemplateBody/TemplateURL
// to null when neither is supplied. Without this guard a later CreateStackInstances would
// deploy empty ("{}") stacks into every target account.
if (templateBody == null || templateBody.isBlank()) {
throw new AwsException("ValidationError",
"Either TemplateBody or TemplateURL must be specified", 400);
}
StackSet ss = new StackSet();
ss.setStackSetName(name);
ss.setStackSetId(name + ":" + UUID.randomUUID());
ss.setTemplateBody(templateBody);
ss.setDescription(description);
if (parameters != null) {
ss.setParameters(new LinkedHashMap<>(parameters));
}
if (capabilities != null) {View on GitHub (pinned to 62ff490619)
Solutions
- Check first: aws --endpoint-url http://localhost:4566 cloudformation describe-stack-set --stack-set-name <name>; only create when absent.
- Delete the existing set before recreating — delete stack instances first (DeleteStackInstances), then DeleteStackSet.
- For ephemeral test runs, use unique names per session (suffix with a run id) or reset the emulator's persistent storage.
Example fix
# before aws ... cloudformation create-stack-set --stack-set-name shared --template-body file://t.yml # after aws ... cloudformation delete-stack-instances --stack-set-name shared \ --accounts 111122223333 --regions us-east-1 --no-retain-stacks || true aws ... cloudformation delete-stack-set --stack-set-name shared || true aws ... cloudformation create-stack-set --stack-set-name shared --template-body file://t.yml
Defensive patterns
Strategy: try-catch
Validate before calling
boolean exists = false;
try {
cfn.describeStackSet(req -> req.stackSetName(name));
exists = true;
} catch (CloudFormationException e) { /* absent */ } Try / catch
catch CloudFormationException with statusCode 409 / code NameAlreadyExistsException: either delete-and-recreate (instances first, then the set) or adopt the existing set; do not blindly retry create.
Prevention
- Make provisioning scripts idempotent: describe-then-create
- Use unique per-run names in ephemeral test environments
- Complete deletion (instances, then set) before recreating the same name
When it happens
Trigger: Calling CreateStackSet twice with the same name without deleting the first, or re-running a setup script against an emulator whose persistent storage still holds the previous StackSet.
Common situations: Idempotent provisioning scripts that create-on-every-run, emulator state persisting between test sessions, or a previous deletion skipped because stack instances remained (DeleteStackSet refuses non-empty sets).
Related errors
AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14).
Data as JSON: /api/errors/fd2635a7d9fff9a0.
Report an issue: GitHub.