Skip to content

Commit dad5a47

Browse files
author
Yuriy Bezsonov
committed
ifra refactoring
1 parent 60972d3 commit dad5a47

25 files changed

Lines changed: 1123 additions & 773 deletions

.kiro/specs/infra/design.md

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public class WorkshopStack extends Stack {
131131
**Database**: Configures RDS Aurora PostgreSQL cluster with universal "workshop-" naming convention
132132
**CodeBuild**: Creates CodeBuild project for AWS service-linked role creation
133133
**Lambda**: Reusable construct for consistent Lambda function creation with inline Python code
134-
**PerformanceAnalysis**: Creates S3 bucket, Lambda functions, and API Gateway for thread dump and profiling analysis
134+
**WorkshopBucket**: Creates shared S3 bucket and SSM parameter for workshop data (uses prefix)
135+
**ThreadAnalysis**: Creates thread dump Lambda and API Gateway for thread analysis (uses prefix)
136+
**JvmAnalysis**: Creates ECR repository and Pod Identity role for jvm-analysis-service (app-specific naming)
135137
**Unicorn**: Creates ECR repository and IAM roles for workshop applications (uses unicorn* naming for workshop content compatibility)
136138

137139
#### CDK Construct Naming Convention
@@ -147,26 +149,70 @@ This convention eliminates CloudFormation logical ID duplication and ensures mai
147149

148150
#### AWS Resource Naming Convention
149151

150-
All AWS resources follow a consistent "workshop-" prefix pattern for operational clarity:
152+
All AWS resources follow a consistent prefix pattern for operational clarity. The prefix is defined as a simple String constant at the beginning of WorkshopStack constructor (defaults to "workshop").
151153

152-
**Lambda Functions:**
153-
- `workshop-codebuild-start` - CodeBuild start trigger
154-
- `workshop-codebuild-report` - CodeBuild completion handler
155-
- `workshop-ide-prefixlist` - CloudFront prefix list lookup
156-
- `workshop-ide-launcher` - EC2 instance launcher with failover
157-
- `workshop-ide-password` - Password retrieval from Secrets Manager
158-
- `workshop-database-setup` - Database schema initialization
154+
**Configurable Prefix Pattern:**
155+
```java
156+
public class WorkshopStack extends Stack {
157+
public WorkshopStack(final Construct scope, final String id, final StackProps props) {
158+
super(scope, id, props);
159+
160+
// Resource naming prefix - change this to customize all resource names
161+
String prefix = "workshop";
162+
163+
// Configuration values - get template type from CDK context (build time)
164+
String templateType = ...
165+
166+
// Pass prefix to all constructs
167+
var ide = new Ide(this, "Ide", Ide.IdeProps.builder()
168+
.prefix(prefix)
169+
.vpc(vpc.getVpc())
170+
.build());
171+
}
172+
}
173+
```
174+
175+
**Lambda Functions (with default "workshop" prefix):**
176+
- `{prefix}-codebuild-start` - CodeBuild start trigger
177+
- `{prefix}-codebuild-report` - CodeBuild completion handler
178+
- `{prefix}-ide-prefixlist` - CloudFront prefix list lookup
179+
- `{prefix}-ide-launcher` - EC2 instance launcher with failover
180+
- `{prefix}-ide-password` - Password retrieval from Secrets Manager
181+
- `{prefix}-database-setup` - Database schema initialization
159182

160183
**CodeBuild Projects:**
161-
- `workshop-setup` - Workshop environment setup and service-linked role creation
184+
- `{prefix}-setup` - Workshop environment setup and service-linked role creation
162185

163186
**CloudWatch Log Groups:**
164-
- `workshop-ide-bootstrap-{timestamp}` - IDE bootstrap logs with unique timestamps
165-
- `/aws/lambda/workshop-*` - All Lambda function logs grouped by prefix
166-
- `/aws/codebuild/workshop-setup` - CodeBuild execution logs
187+
- `{prefix}-ide-bootstrap-{timestamp}` - IDE bootstrap logs with unique timestamps
188+
- `/aws/lambda/{prefix}-*` - All Lambda function logs grouped by prefix
189+
- `/aws/codebuild/{prefix}-setup` - CodeBuild execution logs
190+
191+
**Exceptions (app-specific naming):**
192+
- **Unicorn construct**: Uses "unicorn*" naming for workshop application compatibility
193+
- **JvmAnalysis construct**: Uses "jvm-analysis-*" naming for profiling service resources
194+
195+
**Constructs using prefix:**
196+
- Vpc, Ide, CodeBuild, Database, Eks, WorkshopBucket, ThreadAnalysis
197+
198+
**Constructs with app-specific naming (no prefix):**
199+
- Unicorn (unicorn*), JvmAnalysis (jvm-analysis-*)
200+
201+
**Usage:**
202+
```bash
203+
# Default prefix ("workshop")
204+
npm run generate
205+
206+
# Custom prefix - edit WorkshopStack.java:
207+
# String prefix = "alice";
208+
# Then regenerate:
209+
npm run generate
210+
```
167211

168212
This naming convention enables:
169-
- **Easy filtering** in AWS Console and CLI using `workshop-*` patterns
213+
- **Easy filtering** in AWS Console and CLI using `{prefix}-*` patterns
214+
- **Simple customization** by editing one string constant
215+
- **Reusable templates** by regenerating with different prefix
170216
- **Operational management** through consistent resource identification
171217
- **Cost tracking** and monitoring of workshop-related resources
172218
- **Automated cleanup** and maintenance scripts
@@ -592,6 +638,26 @@ public class BuildConfig {
592638
*For any* EKS cluster and database creation, they should depend only on VPC and deploy in parallel without unnecessary dependencies
593639
**Validates: Requirements 19.1, 19.2, 19.3**
594640

641+
### Property 26: Configurable Prefix Pattern
642+
*For any* AWS resource created by Vpc, Ide, CodeBuild, Database, or Eks constructs, it should use the prefix string defined in WorkshopStack constructor for all resource names
643+
**Validates: Requirements 22.1, 22.2, 22.3, 22.4, 22.5**
644+
645+
### Property 27: Prefix Exception for App-Specific Constructs
646+
*For any* resource created by Unicorn or JvmAnalysis constructs, it should use its own naming convention independent of the WorkshopStack prefix
647+
**Validates: Requirements 22.6, 22.7**
648+
649+
### Property 28: WorkshopBucket Shared Resources
650+
*For any* WorkshopBucket construct, it should create S3 bucket and SSM parameter using the prefix pattern for shared resource discovery
651+
**Validates: Requirements 23.1, 23.2, 23.3**
652+
653+
### Property 29: ThreadAnalysis Infrastructure Naming
654+
*For any* ThreadAnalysis construct, it should use the prefix pattern for all Lambda, API Gateway, IAM role, and security group resources
655+
**Validates: Requirements 24.1, 24.2, 24.3, 24.4, 24.5**
656+
657+
### Property 30: JvmAnalysis App-Specific Naming
658+
*For any* JvmAnalysis construct, it should use "jvm-analysis-*" naming for ECR repository and Pod Identity role
659+
**Validates: Requirements 25.1, 25.2, 25.3**
660+
595661
## Error Handling
596662

597663
### Script Error Handling Strategy

.kiro/specs/infra/requirements.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,50 @@ This document specifies the requirements for creating a new AWS workshop infrast
295295
4. WHEN bootstrap logging is configured, THE system SHALL use "workshop-ide-bootstrap-{timestamp}" pattern for unique log group names
296296
5. WHEN AWS resources are named, THE system SHALL follow the pattern "workshop-{component}-{function}" for operational consistency
297297

298+
### Requirement 22
299+
300+
**User Story:** As a workshop developer, I want configurable resource name prefixes defined in WorkshopStack, so that I can easily customize all resource names by changing a single string constant and regenerating templates.
301+
302+
#### Acceptance Criteria
303+
304+
1. WHEN WorkshopStack constructor begins, THE system SHALL define a prefix String constant at the very beginning (default "workshop")
305+
2. WHEN prefix is defined, THE system SHALL pass it to all construct Props builders that create AWS resources
306+
3. WHEN constructs create AWS resources, THE system SHALL use the prefix for all resource names following pattern "{prefix}-{component}-{function}"
307+
4. WHEN templates need different prefixes, THE developer SHALL edit the prefix string in WorkshopStack.java and run `npm run generate`
308+
5. WHEN CloudFormation template is generated, THE system SHALL have all resource names fully resolved with the prefix value (no runtime parameters)
309+
6. WHEN Unicorn construct creates resources, THE system SHALL use its own "unicorn*" naming convention (exception for app-specific compatibility)
310+
7. WHEN JvmAnalysis construct creates resources, THE system SHALL use "jvm-analysis-*" naming convention (exception for app-specific resources)
311+
312+
313+
314+
### Requirement 23
315+
316+
**User Story:** As a workshop developer, I want shared workshop resources in a dedicated construct, so that S3 bucket and SSM parameter can be reused across multiple features.
317+
318+
#### Acceptance Criteria
319+
320+
1. WHEN WorkshopBucket construct is created, THE system SHALL create an S3 bucket with name pattern `{prefix}-bucket-{account}-{region}-{timestamp}`
321+
2. WHEN WorkshopBucket construct is created, THE system SHALL create an SSM parameter `{prefix}-bucket-name` for bucket name discovery
322+
3. WHEN WorkshopBucket is used by other constructs, THE system SHALL pass the bucket reference for permissions and configuration
323+
324+
### Requirement 24
325+
326+
**User Story:** As a workshop developer, I want thread dump analysis in a dedicated construct, so that thread dump Lambda and API Gateway are clearly separated from other analysis features.
327+
328+
#### Acceptance Criteria
329+
330+
1. WHEN ThreadAnalysis construct is created, THE system SHALL use prefix for all resource names (infrastructure pattern)
331+
2. WHEN ThreadAnalysis creates Lambda, THE system SHALL name it `{prefix}-thread-dump-lambda`
332+
3. WHEN ThreadAnalysis creates API Gateway, THE system SHALL name it `{prefix}-thread-dump-api`
333+
4. WHEN ThreadAnalysis creates IAM role, THE system SHALL name it `{prefix}-thread-dump-lambda-role`
334+
5. WHEN ThreadAnalysis creates security group, THE system SHALL name it `{prefix}-thread-dump-lambda-sg`
335+
336+
### Requirement 25
337+
338+
**User Story:** As a workshop developer, I want JVM profiling analysis in a dedicated construct, so that ECR repository and Pod Identity role are clearly separated as app-specific resources.
339+
340+
#### Acceptance Criteria
341+
342+
1. WHEN JvmAnalysis construct is created, THE system SHALL use app-specific naming (no prefix)
343+
2. WHEN JvmAnalysis creates ECR repository, THE system SHALL name it `jvm-analysis-service`
344+
3. WHEN JvmAnalysis creates Pod Identity role, THE system SHALL name it `jvm-analysis-service-eks-pod-role`

.kiro/specs/infra/tasks.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,110 @@
603603
- No EKS, Database, PerformanceAnalysis, or Unicorn resources ✅
604604
- _Requirements: 1.2, 1.3, 5.4_
605605

606+
607+
608+
## Configurable Prefix Pattern (500.x)
609+
610+
- [x] 500.1 Add prefix constant to WorkshopStack
611+
- Add `String prefix = "workshop";` at the very beginning of WorkshopStack constructor (before configuration values) ✅
612+
- Pass prefix to all construct Props builders (Vpc, Ide, CodeBuild, Database, Eks) ✅
613+
- Do NOT pass prefix to Unicorn or JvmAnalysis (they have their own naming) ✅
614+
- _Requirements: 22.1, 22.2, 22.6, 22.7_
615+
616+
- [x] 500.2 Update Vpc construct for configurable prefix
617+
- Add prefix parameter to VpcProps ✅
618+
- Update VPC name to use `{prefix}-vpc` pattern ✅
619+
- _Requirements: 22.2, 22.3_
620+
621+
- [x] 500.3 Update Ide construct for configurable prefix
622+
- Add prefix parameter to IdeProps ✅
623+
- Update Lambda function names: `{prefix}-ide-launcher`, `{prefix}-ide-password`, `{prefix}-ide-prefixlist`
624+
- Update CloudWatch log group: `{prefix}-ide-bootstrap-{timestamp}`
625+
- Update security group names to use prefix ✅
626+
- Update instance profile name to use prefix ✅
627+
- Update password secret name to use prefix ✅
628+
- _Requirements: 22.2, 22.3_
629+
630+
- [x] 500.4 Update CodeBuild construct for configurable prefix
631+
- Add prefix parameter to CodeBuildProps ✅
632+
- Update CodeBuild project name: `{prefix}-setup`
633+
- Update Lambda function names: `{prefix}-codebuild-start`, `{prefix}-codebuild-report`
634+
- _Requirements: 22.2, 22.3_
635+
636+
- [x] 500.5 Update Database construct for configurable prefix
637+
- Add prefix parameter to DatabaseProps ✅
638+
- Update cluster name: `{prefix}-db-cluster`
639+
- Update instance name: `{prefix}-db-writer`
640+
- Update secrets names: `{prefix}-db-secret`, `{prefix}-db-password-secret`
641+
- Update parameter store: `{prefix}-db-connection-string`
642+
- Update security group name to use prefix ✅
643+
- _Requirements: 22.2, 22.3_
644+
645+
- [x] 500.6 Update Eks construct for configurable prefix
646+
- Add prefix parameter to EksProps ✅
647+
- Update cluster name: `{prefix}-eks`
648+
- _Requirements: 22.2, 22.3_
649+
650+
- [x] 500.7 Update bootstrap scripts for configurable prefix
651+
- Pass PREFIX environment variable from CDK to UserData ✅
652+
- Update userdata.sh to use PREFIX for log group names ✅
653+
- Update bootstrap.sh to use PREFIX for secret name lookup ✅
654+
- Update eks.sh to use PREFIX for cluster name and SecretProviderClass ✅
655+
- Update monitoring.sh and analysis.sh to use PREFIX ✅
656+
- _Requirements: 22.2, 22.3_
657+
658+
- [x] 500.8 Test and validate configurable prefix
659+
- Generate template with default prefix: `npm run generate`
660+
- Verify all resources (except Unicorn and JvmAnalysis) use "workshop-" prefix ✅
661+
- Verify generated CloudFormation template has all names resolved (no parameters) ✅
662+
- _Requirements: 22.4, 22.5_
663+
664+
665+
## PerformanceAnalysis Refactoring (600.x)
666+
667+
- [x] 600.1 Create WorkshopBucket construct
668+
- Create infra/cdk/src/main/java/sample/com/constructs/WorkshopBucket.java ✅
669+
- Add prefix parameter to WorkshopBucketProps ✅
670+
- Create S3 bucket: `{prefix}-bucket-{account}-{region}-{timestamp}`
671+
- Create SSM parameter: `{prefix}-bucket-name`
672+
- Expose bucket and parameter as getters ✅
673+
- _Requirements: 23.1, 23.2, 23.3_
674+
675+
- [x] 600.2 Create ThreadAnalysis construct
676+
- Create infra/cdk/src/main/java/sample/com/constructs/ThreadAnalysis.java ✅
677+
- Add prefix parameter to ThreadAnalysisProps ✅
678+
- Create thread dump Lambda: `{prefix}-thread-dump-lambda`
679+
- Create API Gateway: `{prefix}-thread-dump-api`
680+
- Create Lambda role: `{prefix}-thread-dump-lambda-role`
681+
- Create security group: `{prefix}-thread-dump-lambda-sg`
682+
- Create log group: `/aws/lambda/{prefix}-thread-dump-lambda`
683+
- Accept WorkshopBucket reference for S3 permissions ✅
684+
- _Requirements: 24.1, 24.2, 24.3, 24.4, 24.5_
685+
686+
- [x] 600.3 Create JvmAnalysis construct
687+
- Create infra/cdk/src/main/java/sample/com/constructs/JvmAnalysis.java ✅
688+
- Create ECR repository: `jvm-analysis-service` (no prefix) ✅
689+
- Create Pod Identity role: `jvm-analysis-service-eks-pod-role` (no prefix) ✅
690+
- Accept WorkshopBucket reference for S3 permissions ✅
691+
- _Requirements: 25.1, 25.2, 25.3_
692+
693+
- [x] 600.4 Update WorkshopStack for new constructs
694+
- Add prefix to WorkshopBucket, ThreadAnalysis creation ✅
695+
- Create WorkshopBucket first (shared resource) ✅
696+
- Pass WorkshopBucket to ThreadAnalysis and JvmAnalysis ✅
697+
- Pass WorkshopBucket to Unicorn (replaces performanceAnalysis.getWorkshopBucket()) ✅
698+
- Remove PerformanceAnalysis construct usage ✅
699+
- _Requirements: 22.2, 23.3_
700+
701+
- [x] 600.5 Delete PerformanceAnalysis construct
702+
- Delete infra/cdk/src/main/java/sample/com/constructs/PerformanceAnalysis.java ✅
703+
- Verify all functionality moved to new constructs ✅
704+
- _Requirements: 23.1, 24.1, 25.1_
705+
706+
- [x] 600.6 Test and validate refactoring
707+
- Generate template: `npm run generate`
708+
- Verify WorkshopBucket resources use prefix ✅
709+
- Verify ThreadAnalysis resources use prefix ✅
710+
- Verify JvmAnalysis resources use app-specific naming (no prefix) ✅
711+
- Verify Unicorn still receives bucket reference ✅
712+
- _Requirements: 22.5, 23.3, 24.1, 25.1_

infra/cdk/README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
# Welcome to your CDK Java project!
1+
# Workshop Infrastructure
22

3-
This is a blank project for CDK development with Java.
3+
CDK project for generating CloudFormation templates for AWS workshops.
44

5-
The `cdk.json` file tells the CDK Toolkit how to execute your app.
5+
## Quick Start
66

7-
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
7+
```bash
8+
# Generate all CloudFormation templates
9+
npm run generate
810

9-
## Useful commands
11+
# Sync templates to workshop directories
12+
npm run sync
13+
```
1014

11-
* `mvn package` compile and run tests
12-
* `cdk ls` list all stacks in the app
13-
* `cdk synth` emits the synthesized CloudFormation template
14-
* `cdk deploy` deploy this stack to your default AWS account/region
15-
* `cdk diff` compare deployed stack with current state
16-
* `cdk docs` open CDK documentation
15+
## Customization
1716

18-
Enjoy!
17+
Edit `WorkshopStack.java` to change the resource naming prefix:
18+
```java
19+
String prefix = "workshop"; // Change to customize all resource names
20+
```
21+
22+
Then regenerate templates with `npm run generate`.
23+
24+
## Details
25+
26+
See `.kiro/specs/infra/` for complete requirements, design, and implementation details.

0 commit comments

Comments
 (0)