Skip to content

Commit a8bbe45

Browse files
committed
rename project + remove public VPC and NAT
1 parent f68526b commit a8bbe45

File tree

13 files changed

+83
-166
lines changed

13 files changed

+83
-166
lines changed

Examples/ServiceLifecycle/INFRASTRUCTURE.md renamed to Examples/ServiceLifecycle+Postgres/INFRASTRUCTURE.md

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document describes the AWS infrastructure deployed by the ServiceLifecycle
44

55
## Overview
66

7-
The infrastructure consists of a secure VPC setup with public and private subnets, a PostgreSQL RDS instance in private subnets, and a Lambda function with VPC access. The architecture follows AWS best practices for security and network isolation.
7+
The infrastructure consists of a secure VPC setup with private subnets only, containing both the PostgreSQL RDS instance and Lambda function. The architecture is optimized for cost and security with complete network isolation.
88

99
## Network Architecture
1010

@@ -13,31 +13,22 @@ The infrastructure consists of a secure VPC setup with public and private subnet
1313
- **DNS Support**: DNS hostnames and DNS resolution enabled
1414

1515
### Subnet Layout
16-
- **Public Subnets**:
17-
- Public Subnet 1: `10.0.1.0/24` (AZ 1)
18-
- Public Subnet 2: `10.0.2.0/24` (AZ 2)
19-
- Used for Lambda functions and NAT Gateway
20-
- Auto-assign public IP addresses enabled
21-
2216
- **Private Subnets**:
2317
- Private Subnet 1: `10.0.3.0/24` (AZ 1)
2418
- Private Subnet 2: `10.0.4.0/24` (AZ 2)
25-
- Used for RDS PostgreSQL database
19+
- Used for RDS PostgreSQL database and Lambda function
2620
- No public IP addresses assigned
21+
- Complete isolation from internet
2722

2823
### Network Components
29-
- **Internet Gateway**: Provides internet access for public subnets
30-
- **NAT Gateway**: Deployed in Public Subnet 1, allows private subnets to access the internet
31-
- **Route Tables**:
32-
- Public Route Table: Routes traffic to the Internet Gateway
33-
- Private Route Table: Routes traffic through the NAT Gateway
24+
- **VPC-only architecture**: No internet connectivity required
25+
- **Route Tables**: Default VPC routing for internal communication
3426

3527
## Security Groups
3628

3729
### Lambda Security Group
3830
- **Outbound Rules**:
3931
- PostgreSQL (5432): Restricted to VPC CIDR `10.0.0.0/16`
40-
- HTTPS (443): Open to `0.0.0.0/0` for AWS service access
4132

4233
### Database Security Group
4334
- **Inbound Rules**:
@@ -67,7 +58,7 @@ The infrastructure consists of a secure VPC setup with public and private subnet
6758
- **Architecture**: ARM64
6859
- **Memory**: 512MB
6960
- **Timeout**: 60 seconds
70-
- **Network**: Deployed in public subnets with access to both internet and private resources
61+
- **Network**: Deployed in private subnets with access to database within VPC
7162
- **Environment Variables**:
7263
- `LOG_LEVEL`: trace
7364
- `DB_HOST`: RDS endpoint address
@@ -107,19 +98,64 @@ The template provides several outputs to facilitate working with the deployed re
10798

10899
This infrastructure implements several security best practices:
109100

110-
1. **Network Isolation**: Database is placed in private subnets with no direct internet access
101+
1. **Complete Network Isolation**: Both database and Lambda are in private subnets with no direct acces to or from the internet
111102
2. **Least Privilege**: Security groups restrict traffic to only necessary ports and sources
112103
3. **Encryption**: Database storage is encrypted at rest
113104
4. **Secure Credentials**: Database credentials are managed through AWS Secrets Manager
114105
5. **Secure Communication**: Lambda function connects to database over encrypted connections
115106

116-
## Cost Optimization
117-
118-
The template uses cost-effective resources suitable for development:
119-
120-
- `db.t3.micro` instance (eligible for free tier)
121-
- Minimal storage allocation (20GB)
122-
- No Multi-AZ deployment
123-
- No automated backups
124-
125-
For production workloads, consider adjusting these settings based on your requirements.
107+
## Cost Analysis
108+
109+
### Monthly Cost Breakdown (US East 1 Region)
110+
111+
#### Billable AWS Resources:
112+
113+
**1. RDS PostgreSQL Database**
114+
- Instance (db.t3.micro): $13.87/month (730 hours × $0.019/hour)
115+
- Storage (20GB GP2): $2.30/month (20GB × $0.115/GB/month)
116+
- Backup Storage: $0 (BackupRetentionPeriod: 0)
117+
- Multi-AZ: $0 (disabled)
118+
- **RDS Subtotal: $16.17/month**
119+
120+
**2. AWS Secrets Manager**
121+
- Secret Storage: $0.40/month per secret
122+
- API Calls: ~$0.05 per 10,000 calls (minimal for Lambda access)
123+
- **Secrets Manager Subtotal: ~$0.45/month**
124+
125+
**3. AWS Lambda**
126+
- Memory: 512MB ARM64
127+
- Free Tier: 1M requests + 400,000 GB-seconds/month
128+
- Development Usage: $0 (within free tier)
129+
- **Lambda Subtotal: $0/month**
130+
131+
**4. API Gateway (HTTP API)**
132+
- Free Tier: 1M requests/month
133+
- Development Usage: $0 (within free tier)
134+
- **API Gateway Subtotal: $0/month**
135+
136+
#### Free AWS Resources:
137+
- VPC, Private Subnets, Security Groups, DB Subnet Group: $0
138+
139+
### Total Monthly Cost:
140+
141+
| Service | Cost | Notes |
142+
|---------|------|---------|
143+
| RDS PostgreSQL | $16.17 | db.t3.micro + 20GB storage |
144+
| Secrets Manager | $0.45 | 1 secret + minimal API calls |
145+
| Lambda | $0.00 | Within free tier |
146+
| API Gateway | $0.00 | Within free tier |
147+
| VPC Components | $0.00 | No charges |
148+
| **TOTAL** | **$16.62/month** | |
149+
150+
### With RDS Free Tier (First 12 Months):
151+
- RDS Instance: $0 (750 hours/month free)
152+
- RDS Storage: $0 (20GB free)
153+
- **Total with Free Tier: ~$0.45/month**
154+
155+
### Production Scaling Estimates:
156+
- Higher Lambda usage: +$0.20 per million requests
157+
- More RDS storage: +$0.115 per additional GB/month
158+
- Multi-AZ RDS: ~2x RDS instance cost
159+
- Backup storage: $0.095/GB/month
160+
161+
This architecture provides maximum cost efficiency while maintaining security and functionality for development workloads.

Examples/ServiceLifecycle/README.md renamed to Examples/ServiceLifecycle+Postgres/README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# ServiceLifecycle Lambda with PostgreSQL
1+
# A swift Service Lifecycle Lambda function with a managed PostgreSQL database
22

3-
This example demonstrates a Swift Lambda function that uses ServiceLifecycle to manage a PostgreSQL connection. The function connects to an RDS PostgreSQL database in private subnets and queries user data.
3+
This example demonstrates a Swift Lambda function that uses Swift Service Lifecycle to manage a PostgreSQL connection. The function connects to an RDS PostgreSQL database in private subnets and queries user data.
44

55
## Architecture
66

7-
- **Swift Lambda Function**: Uses ServiceLifecycle to manage PostgreSQL client lifecycle, deployed in public subnets
8-
- **PostgreSQL RDS**: Database instance in private subnets with SSL/TLS encryption
7+
- **Swift Lambda Function**: A network isolated Lambda function that Uses Swift ServiceLifecycle to manage PostgreSQL client lifecycle
8+
- **PostgreSQL on Amazon RDS**: Database instance in private subnets with SSL/TLS encryption
99
- **HTTP API Gateway**: HTTP endpoint to invoke the Lambda function
10-
- **VPC**: Custom VPC with public subnets for Lambda/NAT Gateway and private subnets for RDS
10+
- **VPC**: Custom VPC with private subnets only for complete network isolation
1111
- **Security**: SSL/TLS connections with RDS root certificate verification, secure networking with security groups
1212
- **Timeout Handling**: 3-second timeout mechanism to prevent database connection freeze
1313
- **Secrets Manager**: Secure credential storage and management
1414

15-
For detailed infrastructure information, see `INFRASTRUCTURE.md`.
15+
For detailed infrastructure and cost information, see `INFRASTRUCTURE.md`.
1616

1717
## Implementation Details
1818

@@ -110,7 +110,7 @@ The output will include:
110110

111111
The database is deployed in **private subnets** and is **not directly accessible** from the internet. This follows AWS security best practices.
112112

113-
You may create an Amazon EC2 instance (virtual machine) in the public subnet of the VPC and use it as a jump host to connect to the database. The SAM template doesn't create this for you. [This is left as an exercise to the reader](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html).
113+
To connect to the database, you would need to create an Amazon EC2 instance in a public subnet (which you'd need to add to the VPC) or use AWS Systems Manager Session Manager for secure access to an EC2 instance in a private subnet. The current template uses a private-only architecture for maximum security.
114114

115115
You can access the database connection details in the output of the SAM template:
116116

@@ -171,23 +171,27 @@ sam logs -n ServiceLifecycleLambda --stack-name servicelifecycle-stack --tail
171171
This example follows AWS security best practices:
172172

173173
1. **Private Database**: Database is deployed in private subnets with no internet access
174-
2. **Network Segmentation**: Separate public and private subnets with proper routing
174+
2. **Complete Network Isolation**: Private subnets only with no internet connectivity
175175
3. **Security Groups**: Restrictive security groups following least privilege principle
176176
4. **Secrets Management**: Database credentials stored in AWS Secrets Manager
177177
5. **Encryption**: SSL/TLS for database connections with certificate verification
178-
6. **VPC Endpoints**: Administrative access through SSM VPC endpoints
178+
6. **Minimal Attack Surface**: No public subnets or internet gateways
179179

180180
The infrastructure implements secure networking patterns suitable for production workloads.
181181

182182
## Cost Optimization
183183

184-
The template uses:
184+
The template is optimized for cost:
185185
- `db.t3.micro` instance (eligible for free tier)
186186
- Minimal storage allocation (20GB)
187187
- No Multi-AZ deployment
188188
- No automated backups
189+
- No NAT Gateway or Internet Gateway
190+
- Private-only architecture
189191

190-
For production workloads, adjust these settings based on your requirements.
192+
**Estimated cost: ~$16.62/month (or ~$0.45/month with RDS Free Tier)**
193+
194+
For detailed cost breakdown, see `INFRASTRUCTURE.md`.
191195

192196
## Cleanup
193197

@@ -215,10 +219,9 @@ when deploying with SAM and the `template.yaml` file included in this example, t
215219
### Lambda can't connect to database
216220

217221
1. Check security groups allow traffic on port 5432 between Lambda and RDS security groups
218-
2. Verify the Lambda function is deployed in subnets with proper routing to private subnets
219-
3. Check VPC configuration and routing tables
220-
4. Verify database credentials are correctly retrieved from Secrets Manager and that the Lambda execution policies have permissions to read the secret.
221-
5. Ensure the RDS instance is running and healthy
222+
2. Verify both Lambda and RDS are deployed in the same private subnets
223+
3. Verify database credentials are correctly retrieved from Secrets Manager and that the Lambda execution policies have permissions to read the secret
224+
4. Ensure the RDS instance is running and healthy
222225

223226
### Database connection timeout
224227

0 commit comments

Comments
 (0)