Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions ai/global/cloudformation.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# CloudFormation Instructions

> Load when: any `cloudformation*.json` file or other CloudFormation template is present or being changed.

[Back to Global Instructions Index](index.md)

## Mappings Over Parameters (MANDATORY)

- Put every template value in a mapping (a `Settings` map with a `Values` key, read with `Fn::FindInMap`) unless the deploy action (`.github/actions/cloudformation-deploy/action.yml`) explicitly passes it as a parameter.
- Declare a parameter only when the deploy action supplies it **and** the template uses it. The action supplies only the keys listed in its `Build TemplateParameters file` step (`ApplicationName`, `ApplicationContainer`, `ApplicationVersion`, `ApiPrefix`, `ApiHost`, `AwsContainerRegistry`, `LoadBalancerHostName`, `LoadBalancerPriority`, `Direct1LoadBalancerPriority`, `Direct2LoadBalancerPriority`), and skips any whose value is empty; read the action itself for the current list.
- Reason: `aws cloudformation deploy` keeps an existing stack's previous value for every parameter the action does not pass. A changed parameter `Default` therefore never reaches a live stack, while a changed mapping value is part of the template and is applied on the next deploy.

```json
{
"Mappings": {
"Settings": {
"Values": {
"LogRetentionDays": "30"
}
}
},
"Resources": {
"LogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"RetentionInDays": { "Fn::FindInMap": ["Settings", "Values", "LogRetentionDays"] }
}
}
}
}
```

## Substituting Mapping Values

- Short-form `Fn::Sub` (a single string) can only read parameters, resource attributes and pseudo parameters, not mappings. When a substituted string needs a mapping value (for example a Secrets Manager secret ARN), use long-form `Fn::Sub` with a variable map whose entries come from `Fn::FindInMap`.

```json
{
"Fn::Sub": [
"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretName}",
{
"SecretName": { "Fn::FindInMap": ["Settings", "Values", "SecretName"] }
}
]
}
```

## Naming Existing AWS Resources

- Before a template names an existing AWS resource (for example an IAM role, a cluster or a secret), check the exact name against the sibling service templates that already use it; never infer a name from a naming pattern. A wrong name fails only at deploy time, against the live account.
1 change: 1 addition & 0 deletions ai/global/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Load these only when the work involves the relevant technology or context.
| [shell-scripts.instructions.md](shell-scripts.instructions.md) | Any `.sh` file is present or shell script work is needed | Shebang, linting, output helper conventions (`die`/`success`/`info`), NUL-separated git file lists, argument size limits |
| [shell.firewall.instructions.md](shell.firewall.instructions.md) | Firewall rule management is needed | `firewall-cmd` rules, private network constants |
| [github-workflows.instructions.md](github-workflows.instructions.md) | Any `.github/workflows/*.yml` file is present or being created | Action policy, composite actions, step ordering, permissions, version pinning |
| [cloudformation.instructions.md](cloudformation.instructions.md) | Any `cloudformation*.json` file or other CloudFormation template is present or being changed | Template values as mappings (`Settings`/`Values` with `Fn::FindInMap`) unless the `cloudformation-deploy` action passes them as parameters, declaring only parameters the action supplies and the template uses (a changed parameter `Default` never reaches a live stack), long-form `Fn::Sub` with a `Fn::FindInMap` variable map for mapping values, checking existing AWS resource names against sibling service templates |
| [npm.instructions.md](npm.instructions.md) | Any `package.json` is present or npm packages are being added, updated or installed | Exact version pinning, `--save-exact`, no semver ranges, explicit updates, plain-command npm rules, installing with `npm ci --ignore-scripts` |
| [python.instructions.md](python.instructions.md) | Any `pyproject.toml`, `requirements.txt`, `setup.py`, `setup.cfg`, or `.py` file is present, or Python work is needed | Virtual environment requirement, Python 2 prohibition, latest stable Python 3, idiomatic/modular/testable code style |
| [learnings.instructions.md](learnings.instructions.md) | A memory file (`ai/global` or `ai/local`) is created or updated to record a new learning, or a build, SDK, analyzer, hook or other tooling problem is hit (before blocking) or worked around | Recording a matching human-readable note in the knowledge-base MCP (`kb`), and searching it for recorded tooling fixes |
Expand Down
Loading