@intentius/chant-lexicon-aws 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/plugin.ts CHANGED
@@ -54,7 +54,112 @@ export const awsPlugin: LexiconPlugin = {
54
54
  ];
55
55
  },
56
56
 
57
- initTemplates() {
57
+ initTemplates(template?: string) {
58
+ if (template === "eks") {
59
+ return { src: {
60
+ "infra/cluster.ts": `/**
61
+ * EKS Cluster + Managed Node Group + OIDC Provider
62
+ */
63
+
64
+ import { Cluster, Nodegroup, OIDCProvider, Role, InstanceProfile, Sub, AWS } from "@intentius/chant-lexicon-aws";
65
+
66
+ // EKS Cluster Role
67
+ export const clusterRole = new Role({
68
+ RoleName: Sub\`\${AWS.StackName}-eks-cluster-role\`,
69
+ AssumeRolePolicyDocument: {
70
+ Version: "2012-10-17",
71
+ Statement: [{
72
+ Effect: "Allow",
73
+ Principal: { Service: "eks.amazonaws.com" },
74
+ Action: "sts:AssumeRole",
75
+ }],
76
+ },
77
+ ManagedPolicyArns: [
78
+ "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
79
+ ],
80
+ });
81
+
82
+ // EKS Cluster
83
+ export const cluster = new Cluster({
84
+ Name: Sub\`\${AWS.StackName}-cluster\`,
85
+ RoleArn: clusterRole,
86
+ Version: "1.29",
87
+ });
88
+
89
+ // Node Role
90
+ export const nodeRole = new Role({
91
+ RoleName: Sub\`\${AWS.StackName}-eks-node-role\`,
92
+ AssumeRolePolicyDocument: {
93
+ Version: "2012-10-17",
94
+ Statement: [{
95
+ Effect: "Allow",
96
+ Principal: { Service: "ec2.amazonaws.com" },
97
+ Action: "sts:AssumeRole",
98
+ }],
99
+ },
100
+ ManagedPolicyArns: [
101
+ "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy",
102
+ "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",
103
+ "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly",
104
+ ],
105
+ });
106
+
107
+ // Managed Node Group
108
+ export const nodeGroup = new Nodegroup({
109
+ ClusterName: cluster,
110
+ NodegroupName: Sub\`\${AWS.StackName}-nodes\`,
111
+ NodeRole: nodeRole,
112
+ ScalingConfig: {
113
+ MinSize: 2,
114
+ MaxSize: 10,
115
+ DesiredSize: 3,
116
+ },
117
+ InstanceTypes: ["t3.medium"],
118
+ });
119
+ `,
120
+ "k8s/namespace.ts": `/**
121
+ * K8s namespace with quotas and network isolation
122
+ */
123
+
124
+ import { NamespaceEnv } from "@intentius/chant-lexicon-k8s";
125
+
126
+ export const { namespace, resourceQuota, limitRange, networkPolicy } = NamespaceEnv({
127
+ name: "prod",
128
+ cpuQuota: "16",
129
+ memoryQuota: "32Gi",
130
+ defaultCpuRequest: "100m",
131
+ defaultMemoryRequest: "128Mi",
132
+ defaultCpuLimit: "500m",
133
+ defaultMemoryLimit: "512Mi",
134
+ defaultDenyIngress: true,
135
+ });
136
+ `,
137
+ "k8s/app.ts": `/**
138
+ * Application deployment with IRSA and autoscaling
139
+ */
140
+
141
+ import { AutoscaledService, IrsaServiceAccount } from "@intentius/chant-lexicon-k8s";
142
+
143
+ // IRSA ServiceAccount — replace with your IAM Role ARN from CloudFormation outputs
144
+ export const { serviceAccount } = IrsaServiceAccount({
145
+ name: "app-sa",
146
+ iamRoleArn: "arn:aws:iam::123456789012:role/app-role", // TODO: update from CF output
147
+ namespace: "prod",
148
+ });
149
+
150
+ export const { deployment, service, hpa, pdb } = AutoscaledService({
151
+ name: "my-app",
152
+ image: "my-app:1.0",
153
+ port: 8080,
154
+ maxReplicas: 10,
155
+ cpuRequest: "200m",
156
+ memoryRequest: "256Mi",
157
+ namespace: "prod",
158
+ });
159
+ `,
160
+ } };
161
+ }
162
+
58
163
  return { src: {
59
164
  "config.ts": `/**
60
165
  * Shared bucket configuration — encryption, versioning, public access
@@ -793,6 +898,218 @@ aws cloudformation wait stack-update-complete --stack-name my-app-prod`,
793
898
  },
794
899
  ],
795
900
  },
901
+ {
902
+ name: "chant-eks",
903
+ description: "EKS end-to-end workflow — provision cluster, configure kubectl, deploy K8s workloads",
904
+ content: `---
905
+ skill: chant-eks
906
+ description: End-to-end EKS workflow bridging AWS infrastructure and Kubernetes workloads
907
+ user-invocable: true
908
+ ---
909
+
910
+ # EKS End-to-End Workflow
911
+
912
+ ## Overview
913
+
914
+ This skill bridges two lexicons:
915
+ - **\`@intentius/chant-lexicon-aws\`** — EKS cluster, node groups, IAM roles, OIDC provider (CloudFormation)
916
+ - **\`@intentius/chant-lexicon-k8s\`** — Kubernetes workloads, IRSA, ALB Ingress, storage, observability (K8s YAML)
917
+
918
+ ## Architecture
919
+
920
+ \`\`\`
921
+ AWS Lexicon (CloudFormation) K8s Lexicon (kubectl apply)
922
+ ┌────────────────────────┐ ┌────────────────────────────┐
923
+ │ VPC + Subnets │ │ NamespaceEnv (quotas) │
924
+ │ EKS Cluster │ │ AutoscaledService (app) │
925
+ │ Managed Node Group │──ARNs──→ │ IrsaServiceAccount (IRSA) │
926
+ │ OIDC Provider │ │ AlbIngress (ALB) │
927
+ │ IAM Roles (IRSA) │ │ EbsStorageClass (gp3) │
928
+ │ EKS Add-ons │ │ FluentBitAgent (logs) │
929
+ └────────────────────────┘ │ ExternalDnsAgent (DNS) │
930
+ └────────────────────────────┘
931
+ \`\`\`
932
+
933
+ ## Step 1: Provision AWS Infrastructure
934
+
935
+ \`\`\`bash
936
+ # Build CloudFormation template
937
+ chant build src/infra/ --output infra.json
938
+
939
+ # Deploy
940
+ aws cloudformation deploy \\
941
+ --template-file infra.json \\
942
+ --stack-name my-eks-cluster \\
943
+ --capabilities CAPABILITY_NAMED_IAM
944
+ \`\`\`
945
+
946
+ Key AWS resources:
947
+ - **EKS Cluster** — control plane
948
+ - **Managed Node Group** — EC2 worker nodes
949
+ - **OIDC Provider** — enables IRSA (IAM Roles for Service Accounts)
950
+ - **IAM Roles** — node role, app IRSA roles, ALB controller role
951
+
952
+ ## Step 2: Configure kubectl
953
+
954
+ \`\`\`bash
955
+ aws eks update-kubeconfig --name my-cluster --region us-east-1
956
+ kubectl get nodes # verify connectivity
957
+ \`\`\`
958
+
959
+ ## Step 3: Deploy K8s Workloads
960
+
961
+ \`\`\`bash
962
+ # Build K8s manifests
963
+ chant build src/k8s/ --output manifests.yaml
964
+
965
+ # Apply
966
+ kubectl apply -f manifests.yaml
967
+ \`\`\`
968
+
969
+ ### Key K8s composites for EKS
970
+
971
+ \`\`\`typescript
972
+ import {
973
+ NamespaceEnv,
974
+ AutoscaledService,
975
+ IrsaServiceAccount,
976
+ AlbIngress,
977
+ EbsStorageClass,
978
+ FluentBitAgent,
979
+ ExternalDnsAgent,
980
+ } from "@intentius/chant-lexicon-k8s";
981
+
982
+ // 1. Namespace with quotas and network isolation
983
+ const ns = NamespaceEnv({
984
+ name: "prod",
985
+ cpuQuota: "16",
986
+ memoryQuota: "32Gi",
987
+ defaultCpuRequest: "100m",
988
+ defaultMemoryRequest: "128Mi",
989
+ defaultDenyIngress: true,
990
+ });
991
+
992
+ // 2. IRSA ServiceAccount (use IAM Role ARN from CloudFormation outputs)
993
+ const irsa = IrsaServiceAccount({
994
+ name: "app-sa",
995
+ iamRoleArn: "arn:aws:iam::123456789012:role/app-role", // from CF output
996
+ namespace: "prod",
997
+ });
998
+
999
+ // 3. Application with autoscaling
1000
+ const app = AutoscaledService({
1001
+ name: "api",
1002
+ image: "api:1.0",
1003
+ port: 8080,
1004
+ maxReplicas: 10,
1005
+ cpuRequest: "200m",
1006
+ memoryRequest: "256Mi",
1007
+ namespace: "prod",
1008
+ });
1009
+
1010
+ // 4. ALB Ingress (use ACM cert ARN from CloudFormation outputs)
1011
+ const ingress = AlbIngress({
1012
+ name: "api-ingress",
1013
+ hosts: [{ hostname: "api.example.com", paths: [{ path: "/", serviceName: "api", servicePort: 80 }] }],
1014
+ certificateArn: "arn:aws:acm:us-east-1:123456789012:certificate/abc", // from CF output
1015
+ namespace: "prod",
1016
+ });
1017
+
1018
+ // 5. Storage
1019
+ const storage = EbsStorageClass({ name: "gp3-encrypted", type: "gp3", encrypted: true });
1020
+
1021
+ // 6. Observability
1022
+ const logging = FluentBitAgent({
1023
+ logGroup: "/aws/eks/my-cluster/containers",
1024
+ region: "us-east-1",
1025
+ clusterName: "my-cluster",
1026
+ });
1027
+
1028
+ // 7. DNS
1029
+ const dns = ExternalDnsAgent({
1030
+ iamRoleArn: "arn:aws:iam::123456789012:role/external-dns-role",
1031
+ domainFilters: ["example.com"],
1032
+ });
1033
+ \`\`\`
1034
+
1035
+ ## Step 4: Verify
1036
+
1037
+ \`\`\`bash
1038
+ kubectl get pods -n prod
1039
+ kubectl get ingress -n prod
1040
+ kubectl logs -n amazon-cloudwatch -l app.kubernetes.io/name=fluent-bit
1041
+ \`\`\`
1042
+
1043
+ ## Cleanup
1044
+
1045
+ \`\`\`bash
1046
+ # Delete K8s workloads first
1047
+ kubectl delete -f manifests.yaml
1048
+
1049
+ # Then delete AWS infrastructure
1050
+ aws cloudformation delete-stack --stack-name my-eks-cluster
1051
+ aws cloudformation wait stack-delete-complete --stack-name my-eks-cluster
1052
+ \`\`\`
1053
+
1054
+ ## Cross-Lexicon Value Flow
1055
+
1056
+ CloudFormation outputs flow into K8s composite props:
1057
+
1058
+ | CloudFormation Output | K8s Composite Prop |
1059
+ |----------------------|-------------------|
1060
+ | App IAM Role ARN | \`IrsaServiceAccount.iamRoleArn\` |
1061
+ | ALB Controller Role ARN | \`IrsaServiceAccount.iamRoleArn\` (for ALB controller SA) |
1062
+ | ACM Certificate ARN | \`AlbIngress.certificateArn\` |
1063
+ | ExternalDNS Role ARN | \`ExternalDnsAgent.iamRoleArn\` |
1064
+ | EKS Cluster Name | \`FluentBitAgent.clusterName\`, \`AdotCollector.clusterName\` |
1065
+ | EFS Filesystem ID | \`EfsStorageClass.fileSystemId\` |
1066
+
1067
+ ## EKS Init Template
1068
+
1069
+ Scaffold a dual-lexicon EKS project:
1070
+
1071
+ \`\`\`bash
1072
+ chant init --lexicon aws --template eks
1073
+ \`\`\`
1074
+
1075
+ This creates:
1076
+ - \`src/infra/\` — EKS cluster, node group, IAM (AWS lexicon)
1077
+ - \`src/k8s/\` — namespace, app, ingress, storage (K8s lexicon)
1078
+ - \`package.json\` with both \`@intentius/chant-lexicon-aws\` and \`@intentius/chant-lexicon-k8s\`
1079
+ `,
1080
+ triggers: [
1081
+ { type: "context", value: "eks" },
1082
+ { type: "context", value: "kubernetes" },
1083
+ { type: "context", value: "k8s-workloads" },
1084
+ ],
1085
+ preConditions: [
1086
+ "AWS CLI is installed and configured",
1087
+ "chant CLI is installed",
1088
+ "kubectl is installed",
1089
+ ],
1090
+ postConditions: [
1091
+ "EKS cluster is running",
1092
+ "K8s workloads are deployed",
1093
+ ],
1094
+ parameters: [],
1095
+ examples: [
1096
+ {
1097
+ title: "Full EKS deployment",
1098
+ description: "Deploy infrastructure and workloads end-to-end",
1099
+ input: "Set up a complete EKS environment with my API",
1100
+ output: `# 1. Build and deploy infrastructure
1101
+ chant build src/infra/ --output infra.json
1102
+ aws cloudformation deploy --template-file infra.json --stack-name my-eks --capabilities CAPABILITY_NAMED_IAM
1103
+
1104
+ # 2. Configure kubectl
1105
+ aws eks update-kubeconfig --name my-cluster
1106
+
1107
+ # 3. Build and deploy workloads
1108
+ chant build src/k8s/ --output manifests.yaml
1109
+ kubectl apply -f manifests.yaml`,
1110
+ },
1111
+ ],
1112
+ },
796
1113
  ];
797
1114
  },
798
1115