cdk-infrastructure-patterns
Skill8 starsChanged 41 days agoApache-2.0View on GitHub
AWS CDK Python patterns for stacks, constructs, tagging, cdk-nag, CloudFront, Cognito, S3. Use when writing or reviewing CDK infrastructure code.
In this repository17 other files it gives its agents.
- AGENTSAGENTS.md
- amazon-bedrockSkill
- amazon-location-serviceSkill
- amazon-polly-generativeSkill
- aws-architecture-diagramSkill
- aws-diagram-htmlSkill
- aws-diagram-pngSkill
- aws-serverless-patternsSkill
- cognito-email-migrationSkill
- cognito-passkey-authSkill
- deploy-on-awsSkill
- email-template-renderingSkill
- mcp-tool-discoverySkill
- personal-rules-managementSkill
- react-frontend-patternsSkill
- reinvent-stack-toolkitSkill
- testing-patternsSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 92
Keep tagging every stack with project=<name> (see Stack Template).
- Distinctive: line 96
NEVER use default stack names (CdkStack, Stack)
- Distinctive: line 98
Only add/remove ONE GSI per deploy
- Distinctive: line 99
Always include cdk-nag AwsSolutionsChecks
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CDK Infrastructure Patterns
When uncertain about a CloudFormation/CDK construct, IAM action, or service limit, resolve and call the AWS docs-search / skill-retrieval tools from the
aws-mcp-serverMCP server (search_documentation,retrieve_skill) — seesteering/aws-agent-toolkit.md→ "Resolving the correct tool name" before hardcoding either the bareaws___xor fully-qualifiedmcp_aws_mcp_server_aws___xform, since either can fail with "Tool is not available" depending on the session. If unsure which MCP tool to invoke, seeskills/mcp-tool-discovery/SKILL.mdfor the discovery flow.
Stack Template
from aws_cdk import Stack, Tags, Aspects, Duration
from cdk_nag import AwsSolutionsChecks
class MyAppStack(Stack):
def __init__(self, scope, construct_id, **kwargs):
super().__init__(scope, construct_id, **kwargs)
Tags.of(self).add('auto-stop', 'false')
Tags.of(self).add('auto-delete', 'false')
Tags.of(self).add('project', 'my-app')App Entry Point
app = cdk.App()
stack = MyAppStack(app, "MyAppDevStack", env=cdk.Environment(account="123456789", region="us-east-1"))
Aspects.of(app).add(AwsSolutionsChecks())
app.synth()CloudFront + S3 (OAC, not OAI)
distribution = cloudfront.Distribution(self, "CDN",
default_behavior=cloudfront.BehaviorOptions(
origin=origins.S3BucketOrigin.with_origin_access_control(bucket),
viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
),
default_root_object="index.html",
error_responses=[cloudfront.ErrorResponse(http_status=404, response_page_path="/index.html", response_http_status=200)],
)Cognito
user_pool = cognito.UserPool(self, "UserPool",
self_sign_up_enabled=True,
sign_in_aliases=cognito.SignInAliases(email=True),
# mfa omitted — CDK default is Mfa.OFF. Never force MFA unless a developer
# explicitly asks for it (see security-policies.md "Authentication").
managed_login_version=cognito.ManagedLoginVersion.NEWER_MANAGED_LOGIN,
)DynamoDB
table = dynamodb.Table(self, "Table",
partition_key=dynamodb.Attribute(name="PK", type=dynamodb.AttributeType.STRING),
sort_key=dynamodb.Attribute(name="SK", type=dynamodb.AttributeType.STRING),
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
point_in_time_recovery=True,
# Do NOT set `encryption=` — omitting it keeps DynamoDB's default (AWS_OWNED) encryption.
# Never change to AWS_MANAGED/CUSTOMER_MANAGED. See steering/aws-cdk-core.md "DynamoDB".
)Resource Group (tag-based)
Replaces Service Catalog AppRegistry / myApplications (both moved to maintenance 2026-06-30). Stable construct, no alpha package — groups every resource tagged project=<name>. (This is an L1 Cfn* because aws-cdk-lib has no L2 for Resource Groups as of CDK 2.260 — re-check on upgrade and switch to an L2 if one ships.)
from aws_cdk import aws_resourcegroups as resourcegroups
resourcegroups.CfnGroup(self, "AppResourceGroup",
name="my-app-us-east-1", # unique per account per region
resource_query=resourcegroups.CfnGroup.ResourceQueryProperty(
type="TAG_FILTERS_1_0",
query=resourcegroups.CfnGroup.QueryProperty(
resource_type_filters=["AWS::AllSupported"],
tag_filters=[
resourcegroups.CfnGroup.TagFilterProperty(key="project", values=["my-app"]),
],
),
),
)Keep tagging every stack with project=<name> (see Stack Template). Full rule + the NON-DESTRUCTIVE AppRegistry→Resource Groups migration procedure: steering/aws-cdk-core.md.
Rules
- NEVER use default stack names (CdkStack, Stack)
- Let CDK auto-generate S3 bucket names
- Only add/remove ONE GSI per deploy
- Always include cdk-nag AwsSolutionsChecks
- Prefer L2/L3 constructs; use an L1
Cfn*only when no L2/L3 exists — when you reach for an L1, check whether the currentaws-cdk-libnow ships a higher-level construct (via the AWS docs-search tool, resolved throughtool_searchpersteering/aws-agent-toolkit.md, or PyPI) and propose it instead; re-check on each CDK upgrade - deploy.sh is the ONLY deployment method
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

