@phila/cli 0.0.17 → 0.0.18
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/dist/templates/lambda-api-nodejs/README.md.tmpl +52 -4
- package/dist/templates/lambda-dynamo-api/README.md.tmpl +52 -4
- package/dist/templates/lambda-postgres-api/README.md.tmpl +53 -5
- package/dist/templates/webapp-lambda-dotnet/README.md.tmpl +28 -5
- package/dist/templates/webapp-lambda-dynamo-dotnet/README.md.tmpl +28 -5
- package/dist/templates/webapp-lambda-dynamo-node/README.md.tmpl +28 -5
- package/dist/templates/webapp-lambda-node/README.md.tmpl +28 -5
- package/dist/templates/webapp-lambda-postgres-dotnet/README.md.tmpl +29 -6
- package/dist/templates/webapp-lambda-postgres-node/README.md.tmpl +28 -5
- package/package.json +2 -2
|
@@ -83,6 +83,51 @@ Or use the City CLI:
|
|
|
83
83
|
city config list --env dev
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
+
## API Authentication
|
|
87
|
+
|
|
88
|
+
The API uses path-based authentication with two endpoint patterns:
|
|
89
|
+
|
|
90
|
+
| Path Pattern | Authentication | Use Case |
|
|
91
|
+
|--------------|----------------|----------|
|
|
92
|
+
| `/public/*` | None | Health checks, public data, webhooks |
|
|
93
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
94
|
+
|
|
95
|
+
### Using Protected Endpoints
|
|
96
|
+
|
|
97
|
+
Protected endpoints require the `x-api-key` header. The API key is stored in AWS Secrets Manager and encrypted with a dedicated KMS key.
|
|
98
|
+
|
|
99
|
+
**Retrieve the API key:**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Get the secret ARN from Parameter Store
|
|
103
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
104
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
105
|
+
--query Parameter.Value --output text)
|
|
106
|
+
|
|
107
|
+
# Retrieve the API key value
|
|
108
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
109
|
+
--secret-id "$SECRET_ARN" \
|
|
110
|
+
--query SecretString --output text)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Call a protected endpoint:**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
curl -H "x-api-key: $API_KEY" \
|
|
117
|
+
"https://<api-id>.execute-api.us-east-1.amazonaws.com/dev/private/key/items"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### API Key Rotation
|
|
121
|
+
|
|
122
|
+
API keys are **not** automatically rotated. When you need to rotate:
|
|
123
|
+
|
|
124
|
+
1. Generate a new secret value in Secrets Manager
|
|
125
|
+
2. Update the API Gateway API key
|
|
126
|
+
3. Coordinate with all API consumers to update their keys
|
|
127
|
+
4. Delete the old API key after migration
|
|
128
|
+
|
|
129
|
+
This manual approach ensures controlled rollover without breaking existing integrations.
|
|
130
|
+
|
|
86
131
|
## Routing with philaroute
|
|
87
132
|
|
|
88
133
|
This template uses [@phila/philaroute](https://www.npmjs.com/package/@phila/philaroute) for HTTP routing. Routes are defined using a composable pipeline pattern.
|
|
@@ -179,12 +224,15 @@ To add a database to your API:
|
|
|
179
224
|
## Resources Created
|
|
180
225
|
|
|
181
226
|
This application creates:
|
|
182
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
227
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
228
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
229
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
230
|
+
- **KMS Key** - Encrypts the API key secret (auto-rotates annually)
|
|
231
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
183
232
|
- **Lambda Function** - Serverless compute for handling requests
|
|
184
|
-
- **VPC Security Group** - Network security for Lambda
|
|
185
233
|
- **IAM Role** - Permissions for Lambda execution
|
|
186
|
-
- **SSM Parameters** - Resource discovery (API URL,
|
|
187
|
-
- **CloudWatch Logs** - Application logs
|
|
234
|
+
- **SSM Parameters** - Resource discovery (API URL, API key secret ARN)
|
|
235
|
+
- **CloudWatch Logs** - Application and API Gateway access logs
|
|
188
236
|
|
|
189
237
|
## Next Steps
|
|
190
238
|
|
|
@@ -83,6 +83,51 @@ Or use the City CLI:
|
|
|
83
83
|
city config list --env dev
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
+
## API Authentication
|
|
87
|
+
|
|
88
|
+
The API uses path-based authentication with two endpoint patterns:
|
|
89
|
+
|
|
90
|
+
| Path Pattern | Authentication | Use Case |
|
|
91
|
+
|--------------|----------------|----------|
|
|
92
|
+
| `/public/*` | None | Health checks, public data, webhooks |
|
|
93
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
94
|
+
|
|
95
|
+
### Using Protected Endpoints
|
|
96
|
+
|
|
97
|
+
Protected endpoints require the `x-api-key` header. The API key is stored in AWS Secrets Manager and encrypted with a dedicated KMS key.
|
|
98
|
+
|
|
99
|
+
**Retrieve the API key:**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Get the secret ARN from Parameter Store
|
|
103
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
104
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
105
|
+
--query Parameter.Value --output text)
|
|
106
|
+
|
|
107
|
+
# Retrieve the API key value
|
|
108
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
109
|
+
--secret-id "$SECRET_ARN" \
|
|
110
|
+
--query SecretString --output text)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Call a protected endpoint:**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
curl -H "x-api-key: $API_KEY" \
|
|
117
|
+
"https://<api-id>.execute-api.us-east-1.amazonaws.com/dev/private/key/items"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### API Key Rotation
|
|
121
|
+
|
|
122
|
+
API keys are **not** automatically rotated. When you need to rotate:
|
|
123
|
+
|
|
124
|
+
1. Generate a new secret value in Secrets Manager
|
|
125
|
+
2. Update the API Gateway API key
|
|
126
|
+
3. Coordinate with all API consumers to update their keys
|
|
127
|
+
4. Delete the old API key after migration
|
|
128
|
+
|
|
129
|
+
This manual approach ensures controlled rollover without breaking existing integrations.
|
|
130
|
+
|
|
86
131
|
## DynamoDB Operations
|
|
87
132
|
|
|
88
133
|
The template includes example CRUD operations using AWS SDK v3:
|
|
@@ -159,13 +204,16 @@ The default table uses a single partition key (`pk`). To modify:
|
|
|
159
204
|
## Resources Created
|
|
160
205
|
|
|
161
206
|
This application creates:
|
|
162
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
207
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
208
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
209
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
210
|
+
- **KMS Key** - Encrypts the API key secret (auto-rotates annually)
|
|
211
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
163
212
|
- **Lambda Function** - Serverless compute for handling requests
|
|
164
213
|
- **DynamoDB Table** - NoSQL database with pay-per-request billing
|
|
165
|
-
- **VPC Security Group** - Network security for Lambda
|
|
166
214
|
- **IAM Role** - Permissions for Lambda execution (DynamoDB read/write)
|
|
167
|
-
- **SSM Parameters** - Resource discovery (API URL, Table Name,
|
|
168
|
-
- **CloudWatch Logs** - Application logs
|
|
215
|
+
- **SSM Parameters** - Resource discovery (API URL, Table Name, API key secret ARN)
|
|
216
|
+
- **CloudWatch Logs** - Application and API Gateway access logs
|
|
169
217
|
|
|
170
218
|
## Next Steps
|
|
171
219
|
|
|
@@ -83,6 +83,51 @@ Or use the City CLI:
|
|
|
83
83
|
city config list --env dev
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
+
## API Authentication
|
|
87
|
+
|
|
88
|
+
The API uses path-based authentication with two endpoint patterns:
|
|
89
|
+
|
|
90
|
+
| Path Pattern | Authentication | Use Case |
|
|
91
|
+
|--------------|----------------|----------|
|
|
92
|
+
| `/public/*` | None | Health checks, public data, webhooks |
|
|
93
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
94
|
+
|
|
95
|
+
### Using Protected Endpoints
|
|
96
|
+
|
|
97
|
+
Protected endpoints require the `x-api-key` header. The API key is stored in AWS Secrets Manager and encrypted with a dedicated KMS key.
|
|
98
|
+
|
|
99
|
+
**Retrieve the API key:**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Get the secret ARN from Parameter Store
|
|
103
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
104
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
105
|
+
--query Parameter.Value --output text)
|
|
106
|
+
|
|
107
|
+
# Retrieve the API key value
|
|
108
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
109
|
+
--secret-id "$SECRET_ARN" \
|
|
110
|
+
--query SecretString --output text)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Call a protected endpoint:**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
curl -H "x-api-key: $API_KEY" \
|
|
117
|
+
"https://<api-id>.execute-api.us-east-1.amazonaws.com/dev/private/key/items"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### API Key Rotation
|
|
121
|
+
|
|
122
|
+
API keys are **not** automatically rotated. When you need to rotate:
|
|
123
|
+
|
|
124
|
+
1. Generate a new secret value in Secrets Manager
|
|
125
|
+
2. Update the API Gateway API key
|
|
126
|
+
3. Coordinate with all API consumers to update their keys
|
|
127
|
+
4. Delete the old API key after migration
|
|
128
|
+
|
|
129
|
+
This manual approach ensures controlled rollover without breaking existing integrations.
|
|
130
|
+
|
|
86
131
|
## Routing with philaroute
|
|
87
132
|
|
|
88
133
|
This template uses [@phila/philaroute](https://www.npmjs.com/package/@phila/philaroute) for HTTP routing. Routes are defined using a composable pipeline pattern.
|
|
@@ -191,14 +236,17 @@ Lambda functions automatically receive:
|
|
|
191
236
|
## Resources Created
|
|
192
237
|
|
|
193
238
|
This application creates:
|
|
194
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
239
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
240
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
241
|
+
- **Secrets Manager Secrets** - API key and database credentials (KMS encrypted)
|
|
242
|
+
- **KMS Keys** - Encrypts API key and database secrets (auto-rotate annually)
|
|
243
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
195
244
|
- **Lambda Function** - Serverless compute for handling requests
|
|
196
245
|
- **RDS PostgreSQL** - Managed database instance
|
|
197
|
-
- **Secrets Manager Secret** - Database credentials
|
|
198
246
|
- **VPC Security Groups** - Network security for Lambda and database
|
|
199
|
-
- **IAM Roles** - Permissions for Lambda and database access
|
|
200
|
-
- **SSM Parameters** - Resource discovery (API URL, database endpoint)
|
|
201
|
-
- **CloudWatch Logs** - Application logs
|
|
247
|
+
- **IAM Roles** - Permissions for Lambda, Secrets Manager, and database access
|
|
248
|
+
- **SSM Parameters** - Resource discovery (API URL, API key secret ARN, database endpoint)
|
|
249
|
+
- **CloudWatch Logs** - Application and API Gateway access logs
|
|
202
250
|
|
|
203
251
|
## Serverless Aurora
|
|
204
252
|
|
|
@@ -112,6 +112,27 @@ This automatically creates a route at `/about`.
|
|
|
112
112
|
|
|
113
113
|
The API uses [.NET Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis) with AWS Lambda hosting.
|
|
114
114
|
|
|
115
|
+
### Authentication
|
|
116
|
+
|
|
117
|
+
The API uses path-based authentication:
|
|
118
|
+
|
|
119
|
+
| Path Pattern | Authentication | Use Case |
|
|
120
|
+
|--------------|----------------|----------|
|
|
121
|
+
| `/public/*` | None | Health checks, public data |
|
|
122
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
123
|
+
|
|
124
|
+
**Retrieve the API key:**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
128
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
129
|
+
--query Parameter.Value --output text)
|
|
130
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
131
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
135
|
+
|
|
115
136
|
### Adding Endpoints
|
|
116
137
|
|
|
117
138
|
Edit `apps/api/Program.cs`:
|
|
@@ -152,15 +173,17 @@ This application creates:
|
|
|
152
173
|
- **Origin Access Control** - Secure S3 access
|
|
153
174
|
|
|
154
175
|
**API:**
|
|
155
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
176
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
177
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
178
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
179
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
156
180
|
- **Lambda Function** - .NET 8 serverless compute
|
|
157
|
-
- **VPC Security Group** - Network security
|
|
158
181
|
- **IAM Role** - Permissions for Lambda execution
|
|
159
182
|
|
|
160
183
|
**Shared:**
|
|
161
|
-
- **SSM Parameters** - Resource discovery
|
|
162
|
-
- **CloudWatch Logs** - Application logs
|
|
163
|
-
- **KMS Keys** - Encryption
|
|
184
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
185
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
186
|
+
- **KMS Keys** - Encryption for secrets
|
|
164
187
|
|
|
165
188
|
## URLs
|
|
166
189
|
|
|
@@ -112,6 +112,27 @@ This automatically creates a route at `/about`.
|
|
|
112
112
|
|
|
113
113
|
The API uses [.NET Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis) with AWS Lambda hosting and DynamoDB.
|
|
114
114
|
|
|
115
|
+
### Authentication
|
|
116
|
+
|
|
117
|
+
The API uses path-based authentication:
|
|
118
|
+
|
|
119
|
+
| Path Pattern | Authentication | Use Case |
|
|
120
|
+
|--------------|----------------|----------|
|
|
121
|
+
| `/public/*` | None | Health checks, public data |
|
|
122
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
123
|
+
|
|
124
|
+
**Retrieve the API key:**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
128
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
129
|
+
--query Parameter.Value --output text)
|
|
130
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
131
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
135
|
+
|
|
115
136
|
### Adding Endpoints
|
|
116
137
|
|
|
117
138
|
Edit `apps/api/Program.cs`:
|
|
@@ -191,16 +212,18 @@ This application creates:
|
|
|
191
212
|
- **Origin Access Control** - Secure S3 access
|
|
192
213
|
|
|
193
214
|
**API:**
|
|
194
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
215
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
216
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
217
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
218
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
195
219
|
- **Lambda Function** - .NET 8 serverless compute
|
|
196
220
|
- **DynamoDB Table** - NoSQL database
|
|
197
|
-
- **VPC Security Group** - Network security
|
|
198
221
|
- **IAM Role** - Permissions for Lambda and DynamoDB
|
|
199
222
|
|
|
200
223
|
**Shared:**
|
|
201
|
-
- **SSM Parameters** - Resource discovery
|
|
202
|
-
- **CloudWatch Logs** - Application logs
|
|
203
|
-
- **KMS Keys** - Encryption
|
|
224
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
225
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
226
|
+
- **KMS Keys** - Encryption for secrets and DynamoDB
|
|
204
227
|
|
|
205
228
|
## URLs
|
|
206
229
|
|
|
@@ -110,6 +110,27 @@ This automatically creates a route at `/about`.
|
|
|
110
110
|
|
|
111
111
|
The API uses [@phila/philaroute](https://www.npmjs.com/package/@phila/philaroute) for HTTP routing with DynamoDB for data persistence.
|
|
112
112
|
|
|
113
|
+
### Authentication
|
|
114
|
+
|
|
115
|
+
The API uses path-based authentication:
|
|
116
|
+
|
|
117
|
+
| Path Pattern | Authentication | Use Case |
|
|
118
|
+
|--------------|----------------|----------|
|
|
119
|
+
| `/public/*` | None | Health checks, public data |
|
|
120
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
121
|
+
|
|
122
|
+
**Retrieve the API key:**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
126
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
127
|
+
--query Parameter.Value --output text)
|
|
128
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
129
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
133
|
+
|
|
113
134
|
### DynamoDB Operations
|
|
114
135
|
|
|
115
136
|
The template includes CRUD operations in `apps/api/index.ts`:
|
|
@@ -157,16 +178,18 @@ This application creates:
|
|
|
157
178
|
- **Origin Access Control** - Secure S3 access
|
|
158
179
|
|
|
159
180
|
**API:**
|
|
160
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
181
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
182
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
183
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
184
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
161
185
|
- **Lambda Function** - Serverless compute
|
|
162
186
|
- **DynamoDB Table** - NoSQL database with encryption
|
|
163
|
-
- **VPC Security Group** - Network security
|
|
164
187
|
- **IAM Role** - Permissions for Lambda and DynamoDB
|
|
165
188
|
|
|
166
189
|
**Shared:**
|
|
167
|
-
- **SSM Parameters** - Resource discovery
|
|
168
|
-
- **CloudWatch Logs** - Application logs
|
|
169
|
-
- **KMS Keys** - Encryption
|
|
190
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
191
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
192
|
+
- **KMS Keys** - Encryption for secrets and DynamoDB
|
|
170
193
|
|
|
171
194
|
## URLs
|
|
172
195
|
|
|
@@ -110,6 +110,27 @@ This automatically creates a route at `/about`.
|
|
|
110
110
|
|
|
111
111
|
The API uses [@phila/philaroute](https://www.npmjs.com/package/@phila/philaroute) for HTTP routing.
|
|
112
112
|
|
|
113
|
+
### Authentication
|
|
114
|
+
|
|
115
|
+
The API uses path-based authentication:
|
|
116
|
+
|
|
117
|
+
| Path Pattern | Authentication | Use Case |
|
|
118
|
+
|--------------|----------------|----------|
|
|
119
|
+
| `/public/*` | None | Health checks, public data |
|
|
120
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
121
|
+
|
|
122
|
+
**Retrieve the API key:**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
126
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
127
|
+
--query Parameter.Value --output text)
|
|
128
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
129
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
133
|
+
|
|
113
134
|
### Adding Endpoints
|
|
114
135
|
|
|
115
136
|
Edit `apps/api/index.ts`:
|
|
@@ -143,15 +164,17 @@ This application creates:
|
|
|
143
164
|
- **Origin Access Control** - Secure S3 access
|
|
144
165
|
|
|
145
166
|
**API:**
|
|
146
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
167
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
168
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
169
|
+
- **Secrets Manager Secret** - Stores API key (KMS encrypted)
|
|
170
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
147
171
|
- **Lambda Function** - Serverless compute
|
|
148
|
-
- **VPC Security Group** - Network security
|
|
149
172
|
- **IAM Role** - Permissions for Lambda execution
|
|
150
173
|
|
|
151
174
|
**Shared:**
|
|
152
|
-
- **SSM Parameters** - Resource discovery
|
|
153
|
-
- **CloudWatch Logs** - Application logs
|
|
154
|
-
- **KMS Keys** - Encryption
|
|
175
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
176
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
177
|
+
- **KMS Keys** - Encryption for secrets
|
|
155
178
|
|
|
156
179
|
## URLs
|
|
157
180
|
|
|
@@ -112,6 +112,27 @@ This automatically creates a route at `/about`.
|
|
|
112
112
|
|
|
113
113
|
The API uses [.NET Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis) with AWS Lambda hosting and PostgreSQL via Npgsql.
|
|
114
114
|
|
|
115
|
+
### Authentication
|
|
116
|
+
|
|
117
|
+
The API uses path-based authentication:
|
|
118
|
+
|
|
119
|
+
| Path Pattern | Authentication | Use Case |
|
|
120
|
+
|--------------|----------------|----------|
|
|
121
|
+
| `/public/*` | None | Health checks, public data |
|
|
122
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
123
|
+
|
|
124
|
+
**Retrieve the API key:**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
128
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
129
|
+
--query Parameter.Value --output text)
|
|
130
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
131
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
135
|
+
|
|
115
136
|
### Adding Endpoints
|
|
116
137
|
|
|
117
138
|
Edit `apps/api/Program.cs`:
|
|
@@ -207,17 +228,19 @@ This application creates:
|
|
|
207
228
|
- **Origin Access Control** - Secure S3 access
|
|
208
229
|
|
|
209
230
|
**API:**
|
|
210
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
231
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
232
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
233
|
+
- **Secrets Manager Secrets** - API key and database credentials (KMS encrypted)
|
|
234
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
211
235
|
- **Lambda Function** - .NET 8 serverless compute
|
|
212
236
|
- **RDS PostgreSQL** - Relational database
|
|
213
|
-
- **Secrets Manager** - Database credentials
|
|
214
237
|
- **VPC Security Group** - Network security
|
|
215
|
-
- **IAM Role** - Permissions for Lambda and database
|
|
238
|
+
- **IAM Role** - Permissions for Lambda, Secrets Manager, and database
|
|
216
239
|
|
|
217
240
|
**Shared:**
|
|
218
|
-
- **SSM Parameters** - Resource discovery
|
|
219
|
-
- **CloudWatch Logs** - Application logs
|
|
220
|
-
- **KMS Keys** - Encryption
|
|
241
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
242
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
243
|
+
- **KMS Keys** - Encryption for secrets
|
|
221
244
|
|
|
222
245
|
## URLs
|
|
223
246
|
|
|
@@ -110,6 +110,27 @@ This automatically creates a route at `/about`.
|
|
|
110
110
|
|
|
111
111
|
The API uses [@phila/philaroute](https://www.npmjs.com/package/@phila/philaroute) for HTTP routing with PostgreSQL for data persistence.
|
|
112
112
|
|
|
113
|
+
### Authentication
|
|
114
|
+
|
|
115
|
+
The API uses path-based authentication:
|
|
116
|
+
|
|
117
|
+
| Path Pattern | Authentication | Use Case |
|
|
118
|
+
|--------------|----------------|----------|
|
|
119
|
+
| `/public/*` | None | Health checks, public data |
|
|
120
|
+
| `/private/key/*` | API Key required | Protected endpoints |
|
|
121
|
+
|
|
122
|
+
**Retrieve the API key:**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
SECRET_ARN=$(aws ssm get-parameter \
|
|
126
|
+
--name "/dev/{{appName}}/api/main/key-secret-arn" \
|
|
127
|
+
--query Parameter.Value --output text)
|
|
128
|
+
API_KEY=$(aws secretsmanager get-secret-value \
|
|
129
|
+
--secret-id "$SECRET_ARN" --query SecretString --output text)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The API key is stored in Secrets Manager, encrypted with a dedicated KMS key. Keys are not auto-rotated; coordinate manual rotation with API consumers.
|
|
133
|
+
|
|
113
134
|
### Database Setup
|
|
114
135
|
|
|
115
136
|
1. Install a PostgreSQL client:
|
|
@@ -157,17 +178,19 @@ This application creates:
|
|
|
157
178
|
- **Origin Access Control** - Secure S3 access
|
|
158
179
|
|
|
159
180
|
**API:**
|
|
160
|
-
- **API Gateway REST API** - HTTP endpoint
|
|
181
|
+
- **API Gateway REST API** - HTTP endpoint with path-based auth
|
|
182
|
+
- **API Key & Usage Plan** - For protected endpoint authentication
|
|
183
|
+
- **Secrets Manager Secrets** - API key and database credentials (KMS encrypted)
|
|
184
|
+
- **WAF Web ACL** - Protects API from common attacks
|
|
161
185
|
- **Lambda Function** - Serverless compute in VPC
|
|
162
186
|
- **RDS PostgreSQL** - Managed relational database
|
|
163
|
-
- **Secrets Manager Secret** - Database credentials
|
|
164
187
|
- **VPC Security Groups** - Network security for Lambda and RDS
|
|
165
188
|
- **IAM Role** - Permissions for Lambda and Secrets Manager
|
|
166
189
|
|
|
167
190
|
**Shared:**
|
|
168
|
-
- **SSM Parameters** - Resource discovery
|
|
169
|
-
- **CloudWatch Logs** - Application logs
|
|
170
|
-
- **KMS Keys** - Encryption
|
|
191
|
+
- **SSM Parameters** - Resource discovery (URLs, API key secret ARN)
|
|
192
|
+
- **CloudWatch Logs** - Application and API access logs
|
|
193
|
+
- **KMS Keys** - Encryption for secrets
|
|
171
194
|
|
|
172
195
|
## URLs
|
|
173
196
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phila/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "CLI tool for City of Philadelphia AWS infrastructure",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"commander": "^11.0.0",
|
|
25
25
|
"fs-extra": "^11.1.0",
|
|
26
26
|
"inquirer": "^8.2.5",
|
|
27
|
-
"@phila/constructs": "0.0.
|
|
27
|
+
"@phila/constructs": "0.0.11",
|
|
28
28
|
"@phila/db-postgres": "0.0.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|