You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Examples/ServiceLifecycle+Postgres/INFRASTRUCTURE.md
+62-26Lines changed: 62 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This document describes the AWS infrastructure deployed by the ServiceLifecycle
4
4
5
5
## Overview
6
6
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.
8
8
9
9
## Network Architecture
10
10
@@ -13,31 +13,22 @@ The infrastructure consists of a secure VPC setup with public and private subnet
13
13
-**DNS Support**: DNS hostnames and DNS resolution enabled
14
14
15
15
### 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
-
22
16
-**Private Subnets**:
23
17
- Private Subnet 1: `10.0.3.0/24` (AZ 1)
24
18
- 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
26
20
- No public IP addresses assigned
21
+
- Complete isolation from internet
27
22
28
23
### 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
34
26
35
27
## Security Groups
36
28
37
29
### Lambda Security Group
38
30
-**Outbound Rules**:
39
31
- 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
41
32
42
33
### Database Security Group
43
34
-**Inbound Rules**:
@@ -67,7 +58,7 @@ The infrastructure consists of a secure VPC setup with public and private subnet
67
58
-**Architecture**: ARM64
68
59
-**Memory**: 512MB
69
60
-**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
71
62
-**Environment Variables**:
72
63
-`LOG_LEVEL`: trace
73
64
-`DB_HOST`: RDS endpoint address
@@ -107,19 +98,64 @@ The template provides several outputs to facilitate working with the deployed re
107
98
108
99
This infrastructure implements several security best practices:
109
100
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
111
102
2.**Least Privilege**: Security groups restrict traffic to only necessary ports and sources
112
103
3.**Encryption**: Database storage is encrypted at rest
113
104
4.**Secure Credentials**: Database credentials are managed through AWS Secrets Manager
114
105
5.**Secure Communication**: Lambda function connects to database over encrypted connections
115
106
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.
Copy file name to clipboardExpand all lines: Examples/ServiceLifecycle+Postgres/README.md
+18-15Lines changed: 18 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
-
# ServiceLifecycle Lambda with PostgreSQL
1
+
# A swift Service Lifecycle Lambda function with a managed PostgreSQL database
2
2
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.
4
4
5
5
## Architecture
6
6
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
9
9
-**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
11
11
-**Security**: SSL/TLS connections with RDS root certificate verification, secure networking with security groups
12
12
-**Timeout Handling**: 3-second timeout mechanism to prevent database connection freeze
13
13
-**Secrets Manager**: Secure credential storage and management
14
14
15
-
For detailed infrastructure information, see `INFRASTRUCTURE.md`.
15
+
For detailed infrastructure and cost information, see `INFRASTRUCTURE.md`.
16
16
17
17
## Implementation Details
18
18
@@ -110,7 +110,7 @@ The output will include:
110
110
111
111
The database is deployed in **private subnets** and is **not directly accessible** from the internet. This follows AWS security best practices.
112
112
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.
114
114
115
115
You can access the database connection details in the output of the SAM template:
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
175
175
3.**Security Groups**: Restrictive security groups following least privilege principle
176
176
4.**Secrets Management**: Database credentials stored in AWS Secrets Manager
177
177
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
179
179
180
180
The infrastructure implements secure networking patterns suitable for production workloads.
181
181
182
182
## Cost Optimization
183
183
184
-
The template uses:
184
+
The template is optimized for cost:
185
185
-`db.t3.micro` instance (eligible for free tier)
186
186
- Minimal storage allocation (20GB)
187
187
- No Multi-AZ deployment
188
188
- No automated backups
189
+
- No NAT Gateway or Internet Gateway
190
+
- Private-only architecture
189
191
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`.
191
195
192
196
## Cleanup
193
197
@@ -215,10 +219,9 @@ when deploying with SAM and the `template.yaml` file included in this example, t
215
219
### Lambda can't connect to database
216
220
217
221
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
0 commit comments