Skip to content

Commit 67a9df7

Browse files
committed
Merge pull request #66 from OleksandrRebenok/fix/existingVpc
Fix of using existing vpc Add dedicated stack s3bucket. Skip networking stack if user choose to use existing VPC. In case of using existing VPC, we pass subnets and vpc to monitoring stack from user input. Fixes #55 # Conflicts: # source/claude_code_with_bedrock/cli/commands/deploy.py
2 parents b4d7c13 + af534b0 commit 67a9df7

File tree

4 files changed

+75
-59
lines changed

4 files changed

+75
-59
lines changed

deployment/infrastructure/networking.yaml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,6 @@ Resources:
9292
RouteTableId: !Ref PublicRouteTable
9393
SubnetId: !Ref PublicSubnet2
9494

95-
# S3 Bucket for CloudFormation artifacts (Lambda code packages)
96-
CfnArtifactsBucket:
97-
Type: AWS::S3::Bucket
98-
Properties:
99-
BucketEncryption:
100-
ServerSideEncryptionConfiguration:
101-
- ServerSideEncryptionByDefault:
102-
SSEAlgorithm: AES256
103-
VersioningConfiguration:
104-
Status: Enabled
105-
LifecycleConfiguration:
106-
Rules:
107-
- Id: DeleteOldVersions
108-
Status: Enabled
109-
NoncurrentVersionExpirationInDays: 30
110-
PublicAccessBlockConfiguration:
111-
BlockPublicAcls: true
112-
BlockPublicPolicy: true
113-
IgnorePublicAcls: true
114-
RestrictPublicBuckets: true
115-
Tags:
116-
- Key: Name
117-
Value: claude-code-cfn-artifacts
118-
- Key: Purpose
119-
Value: CloudFormation Lambda packaging
120-
12195
Outputs:
12296
VpcId:
12397
Description: The ID of the VPC
@@ -143,8 +117,3 @@ Outputs:
143117
Export:
144118
Name: !Sub "${AWS::StackName}-SubnetIds"
145119

146-
CfnArtifactsBucket:
147-
Description: S3 bucket for CloudFormation artifacts
148-
Value: !Ref CfnArtifactsBucket
149-
Export:
150-
Name: !Sub "${AWS::StackName}-CfnArtifactsBucket"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: 'S3 Bucket for CloudFormation artifacts (Lambda code packages)'
3+
4+
Resources:
5+
# S3 Bucket for CloudFormation artifacts (Lambda code packages)
6+
CfnArtifactsBucket:
7+
Type: AWS::S3::Bucket
8+
Properties:
9+
BucketEncryption:
10+
ServerSideEncryptionConfiguration:
11+
- ServerSideEncryptionByDefault:
12+
SSEAlgorithm: AES256
13+
VersioningConfiguration:
14+
Status: Enabled
15+
LifecycleConfiguration:
16+
Rules:
17+
- Id: DeleteOldVersions
18+
Status: Enabled
19+
NoncurrentVersionExpirationInDays: 30
20+
PublicAccessBlockConfiguration:
21+
BlockPublicAcls: true
22+
BlockPublicPolicy: true
23+
IgnorePublicAcls: true
24+
RestrictPublicBuckets: true
25+
Tags:
26+
- Key: Name
27+
Value: claude-code-cfn-artifacts
28+
- Key: Purpose
29+
Value: CloudFormation Lambda packaging
30+
31+
Outputs:
32+
CfnArtifactsBucket:
33+
Description: S3 bucket for CloudFormation artifacts
34+
Value: !Ref CfnArtifactsBucket
35+
Export:
36+
Name: !Sub "${AWS::StackName}-CfnArtifactsBucket"

source/claude_code_with_bedrock/cli/commands/deploy.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,16 @@ def handle(self) -> int:
155155
# Deploy all configured stacks in dependency order
156156
stacks_to_deploy.append(("auth", "Authentication Stack (Cognito + IAM)"))
157157

158-
# Deploy networking first if needed (required by landing-page distribution and monitoring)
159-
if profile.monitoring_enabled or (
160-
profile.enable_distribution and profile.distribution_type == "landing-page"
161-
):
162-
stacks_to_deploy.append(("networking", "VPC Networking for OTEL Collector"))
163-
164158
# Deploy distribution after networking if it's landing-page type
165159
if profile.enable_distribution:
166160
stacks_to_deploy.append(("distribution", "Distribution infrastructure (S3 + IAM)"))
167161

168162
# Deploy remaining monitoring stacks
169163
if profile.monitoring_enabled:
164+
vpc_congig = profile.monitoring_config or {}
165+
if vpc_congig.get("create_vpc", True):
166+
stacks_to_deploy.append(("networking", "VPC Networking for OTEL Collector"))
167+
stacks_to_deploy.append(("s3bucket", "S3 Bucket"))
170168
stacks_to_deploy.append(("monitoring", "OpenTelemetry Collector"))
171169
stacks_to_deploy.append(("dashboard", "CloudWatch Dashboard"))
172170
# Check if analytics is enabled (default to True for backward compatibility)
@@ -563,6 +561,7 @@ def deploy_with_cf(
563561
template = project_root / "deployment" / "infrastructure" / "networking.yaml"
564562
stack_name = profile.stack_names.get("networking", f"{profile.identity_pool_name}-networking")
565563
vpc_config = profile.monitoring_config or {}
564+
566565
params = [
567566
f"VpcCidr={vpc_config.get('vpc_cidr', '10.0.0.0/16')}",
568567
f"PublicSubnet1Cidr={vpc_config.get('subnet1_cidr', '10.0.1.0/24')}",
@@ -572,34 +571,46 @@ def deploy_with_cf(
572571
template, stack_name, params, task_description="Deploying networking infrastructure..."
573572
)
574573

574+
elif stack_type == "s3bucket":
575+
template = project_root / "deployment" / "infrastructure" / "s3bucket.yaml"
576+
stack_name = profile.stack_names.get("networking", f"{profile.identity_pool_name}-s3bucket")
577+
params = []
578+
return deploy_with_cf(template, stack_name, params, task_description="Deploying S3 Bucket...")
575579
elif stack_type == "monitoring":
576580
# Ensure ECS service linked role exists before deploying
577581
self._ensure_ecs_service_linked_role(console)
578582

579583
template = project_root / "deployment" / "infrastructure" / "otel-collector.yaml"
580584
stack_name = profile.stack_names.get("monitoring", f"{profile.identity_pool_name}-otel-collector")
585+
params = []
586+
vpc_congig = profile.monitoring_config or {}
581587

582-
# Get VPC outputs from networking stack
583-
networking_stack_name = profile.stack_names.get(
584-
"networking", f"{profile.identity_pool_name}-networking"
585-
)
586-
networking_outputs = get_stack_outputs(networking_stack_name, profile.aws_region)
588+
if not vpc_congig.get("create_vpc", True):
589+
params.append(f"VpcId={vpc_congig.get('vpc_id', '')}")
590+
subnet_ids = ",".join(vpc_congig.get("subnet_ids", []))
591+
params.append(f"SubnetIds={subnet_ids}")
592+
else:
593+
# Get VPC outputs from networking stack
594+
networking_stack_name = profile.stack_names.get(
595+
"networking", f"{profile.identity_pool_name}-networking"
596+
)
597+
networking_outputs = get_stack_outputs(networking_stack_name, profile.aws_region)
587598

588-
params = []
589-
if networking_outputs:
590-
vpc_id = networking_outputs.get("VpcId", "")
591-
subnet_ids = networking_outputs.get("SubnetIds", "")
592-
if vpc_id:
593-
params.append(f"VpcId={vpc_id}")
594-
if subnet_ids:
595-
params.append(f"SubnetIds={subnet_ids}")
599+
if networking_outputs:
600+
vpc_id = networking_outputs.get("VpcId", "")
601+
subnet_ids = networking_outputs.get("SubnetIds", "")
602+
if vpc_id:
603+
params.append(f"VpcId={vpc_id}")
604+
if subnet_ids:
605+
params.append(f"SubnetIds={subnet_ids}")
596606

597607
# Add HTTPS domain parameters if configured
598608
monitoring_config = getattr(profile, "monitoring_config", {})
599609
if monitoring_config.get("custom_domain"):
600610
params.append(f"CustomDomainName={monitoring_config['custom_domain']}")
601611
params.append(f"HostedZoneId={monitoring_config['hosted_zone_id']}")
602612

613+
console.print(f"[dim]Using parameters: {params}[/dim]")
603614
return deploy_with_cf(
604615
template, stack_name, params, task_description="Deploying monitoring collector..."
605616
)
@@ -609,20 +620,18 @@ def deploy_with_cf(
609620
stack_name = profile.stack_names.get("dashboard", f"{profile.identity_pool_name}-dashboard")
610621

611622
# Get S3 bucket from networking stack for packaging
612-
networking_stack_name = profile.stack_names.get(
613-
"networking", f"{profile.identity_pool_name}-networking"
614-
)
615-
networking_outputs = get_stack_outputs(networking_stack_name, profile.aws_region)
623+
s3_stack_name = profile.stack_names.get("s3", f"{profile.identity_pool_name}-s3bucket")
624+
s3_outputs = get_stack_outputs(s3_stack_name, profile.aws_region)
616625

617-
if not networking_outputs or not networking_outputs.get("CfnArtifactsBucket"):
626+
if not s3_outputs or not s3_outputs.get("CfnArtifactsBucket"):
618627
console.print("[red]Error: S3 bucket for packaging not found[/red]")
619628
console.print(
620629
"[yellow]The networking stack must be deployed first with the artifacts bucket.[/yellow]"
621630
)
622631
console.print("Run: [cyan]ccwb deploy networking[/cyan]")
623632
return 1
624633

625-
s3_bucket = networking_outputs["CfnArtifactsBucket"]
634+
s3_bucket = s3_outputs["CfnArtifactsBucket"]
626635

627636
# Package the template using AWS CLI (simple and reliable!)
628637
task = progress.add_task("Packaging dashboard Lambda functions...", total=None)

source/claude_code_with_bedrock/cli/commands/destroy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def handle(self) -> int:
5050

5151
stacks_to_destroy = []
5252
if stack_arg:
53-
if stack_arg in ["auth", "networking", "monitoring", "dashboard", "analytics"]:
53+
if stack_arg in ["auth", "networking", "monitoring", "dashboard", "analytics", "s3bucket"]:
5454
stacks_to_destroy.append(stack_arg)
5555
else:
5656
console.print(f"[red]Unknown stack: {stack_arg}[/red]")
57-
console.print("Valid stacks: auth, networking, monitoring, dashboard, analytics")
57+
console.print("Valid stacks: auth, networking, monitoring, dashboard, analytics, s3bucket")
5858
return 1
5959
else:
6060
# Destroy all stacks in reverse order
61-
stacks_to_destroy = ["analytics", "dashboard", "monitoring", "networking", "auth"]
61+
stacks_to_destroy = ["analytics", "dashboard", "monitoring", "networking", "s3bucket", "auth"]
6262

6363
# Show what will be destroyed
6464
console.print(
@@ -98,6 +98,8 @@ def handle(self) -> int:
9898
continue
9999
if stack == "analytics" and not profile.monitoring_enabled:
100100
continue
101+
if stack == "s3bucket" and not profile.monitoring_enabled:
102+
continue
101103

102104
stack_name = profile.stack_names.get(stack, f"{profile.identity_pool_name}-{stack}")
103105
console.print(f"Destroying {stack} stack: [cyan]{stack_name}[/cyan]")

0 commit comments

Comments
 (0)