编写云基础设施配置模板
按照仓库规范生成云资源配置,配套权限与数据保留策略、变更集命令及静态检查结果。
完整提示词
<context>
CloudFormation is still the native way many AWS teams manage infrastructure, and its traps are specific. Some property changes replace a resource rather than update it, which for a database or bucket means data loss unless `DeletionPolicy` and `UpdateReplacePolicy` are set to `Retain` or `Snapshot`. Hard-coded physical names block replacement and collide across environments. Deploying with `update-stack` directly hides what will change; change sets show replacements before they happen. Stacks that fail during creation roll back to `ROLLBACK_COMPLETE` and must be deleted before a retry; stacks that fail during update can get stuck in `UPDATE_ROLLBACK_FAILED`. An export cannot be changed or deleted while another stack imports it, so exports freeze the exporting stack's interface. IAM written with wildcards to "make it work" stays forever. `cfn-lint` catches most invalid properties before deploy, and `cfn-guard` or similar can check policy rules.
</context>
<task>
Write a CloudFormation template for:
<resources>
{{resources}}
</resources>
1. Read the repository: existing templates, naming and tagging conventions, how parameters and environments are handled, and the deploy scripts or pipeline. Follow existing conventions and do not introduce a second IaC tool. If the team uses SAM or CDK, say so and ask whether raw CloudFormation is still wanted.
2. Write the template in YAML: `Parameters` with allowed values or patterns, `Conditions` for environment differences, `Mappings` only where a table is clearer, and `Outputs` for values other stacks or apps need (exports only when cross-stack references are really needed).
3. Let CloudFormation generate physical names unless a fixed name is required; when it is, include the environment and explain the replacement consequence.
4. For stateful resources (databases, buckets, tables, queues with important messages) set `DeletionPolicy` and `UpdateReplacePolicy`, and enable encryption, backups or versioning as fits.
5. IAM: one role per consumer, actions and resource ARNs scoped with `!GetAtt` and `!Sub`, no `*` on actions or resources unless the service requires it, in which case comment why.
6. Tag every taggable resource with the project's tags.
7. Deploy: use change sets (`aws cloudformation deploy` creates them; `--no-execute-changeset` to review first; `--capabilities CAPABILITY_IAM` or `CAPABILITY_NAMED_IAM` when the template creates IAM resources), stack termination protection for production, and a stack policy for critical resources if wanted.
8. Run `cfn-lint` on the template if available and fix what it reports.
</task>
<constraints>
- Do not invent resource types, properties or intrinsic function behaviour; mark anything you are unsure of.
- Never put secrets in parameters defaults or the template; use dynamic references to Secrets Manager or SSM SecureString.
- Do not deploy anything; changes are to files only.
{{> guardrails/scope-discipline}}
{{> guardrails/verify-before-done}}
</constraints>
<output_format>
## Template
The path and full YAML template.
## Decisions
One bullet each for naming, retention policies, IAM scope, and conditions or parameters.
## Deploy
The change-set based deploy commands per environment and the review step.
## Verify
`cfn-lint` output or "not run", and what to check in the change set (replacements especially).
## Follow-ups
Termination protection, stack policy, and resources that should move to separate stacks. "None" if empty.
</output_format>可替换内容
- {{resources}}
- {{> guardrails/scope-discipline}}
- {{> guardrails/verify-before-done}}
分类与标签
编程开发、基础设施即代码、云资源配置、权限策略、变更集审核