@exabugs/dynamodb-client 0.6.0 → 0.7.0

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/CHANGELOG.md CHANGED
@@ -7,9 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0] - 2024-12-28
11
+
12
+ ### Added
13
+
14
+ - **Terraform**: KMS access policy for Parameter Store integration
15
+ - Lambda functions can now decrypt SecureString environment variables
16
+ - Added `kms:Decrypt` permission with SSM service condition
17
+ - Enables secure configuration management through Parameter Store
18
+
19
+ ### Changed
20
+
21
+ - **CORS**: Expanded CORS configuration for comprehensive API support
22
+ - Added support for GET, PUT, DELETE, and OPTIONS methods
23
+ - Previously only supported POST method
24
+ - Enables full REST API functionality for react-admin integration
25
+
26
+ ### Improved
27
+
28
+ - **Infrastructure**: Enhanced Lambda function permissions and dependencies
29
+ - Added proper dependency management for KMS policy
30
+ - Improved security with least-privilege access patterns
31
+
10
32
  ## [0.5.0] - 2024-12-23
11
33
 
12
34
  ### Added
35
+
13
36
  - 包括的なAPIリファレンスドキュメント (`docs/API.md`)
14
37
  - 3つの認証方式(IAM、Cognito、Token)の詳細な説明
15
38
  - すべてのクライアントAPIメソッドの完全な仕様
@@ -27,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27
50
  - 開発者・利用者向けのセキュリティベストプラクティス
28
51
 
29
52
  ### Changed
53
+
30
54
  - アーキテクチャリファクタリングによるコード構造の改善
31
55
  - 共通モジュールの抽出 (`src/shared/` ディレクトリ構造)
32
56
  - 大きな関数の分割(handler.ts ~520行 → 複数モジュール)
@@ -35,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
59
  - 依存関係管理と循環依存の解決
36
60
 
37
61
  ### Improved
62
+
38
63
  - コードの可読性と保守性の向上
39
64
  - 単一責任原則に基づく関数分割(50行制限)
40
65
  - 3回以上繰り返されるコードの共通関数化
@@ -248,6 +273,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
248
273
  ### Migration Guide
249
274
 
250
275
  **Before (v0.1.x):**
276
+
251
277
  ```typescript
252
278
  const client = new DynamoClient(apiUrl);
253
279
  await client.connect();
@@ -262,6 +288,7 @@ const dataProvider = createDataProvider({
262
288
  ```
263
289
 
264
290
  **After (v0.2.0):**
291
+
265
292
  ```typescript
266
293
  const client = new DynamoClient(apiUrl);
267
294
  await client.connect();
package/README.md CHANGED
@@ -265,6 +265,77 @@ See the [example project's documentation](https://github.com/exabugs/dynamodb-cl
265
265
 
266
266
  ---
267
267
 
268
+ ## 🔧 Configuration Management
269
+
270
+ ### Parameter Store Integration
271
+
272
+ The library supports AWS Parameter Store for flexible configuration management, eliminating the need for Terraform outputs in application code.
273
+
274
+ #### Parameter Structure
275
+
276
+ Parameters are organized hierarchically:
277
+
278
+ ```
279
+ /{project_name}/{environment}/
280
+ ├── app/
281
+ │ ├── records-api-url # Lambda Function URL
282
+ │ └── admin-ui/
283
+ │ ├── cognito-user-pool-id
284
+ │ ├── cognito-client-id
285
+ │ └── cognito-domain
286
+ ├── infra/
287
+ │ └── dynamodb-table-name
288
+ └── lambda/
289
+ └── records-function-arn
290
+ ```
291
+
292
+ #### Benefits
293
+
294
+ - **🔄 Dynamic Configuration**: Update settings without redeployment
295
+ - **🔐 Secure Storage**: All parameters encrypted with AWS managed KMS keys
296
+ - **💰 Cost Effective**: Standard tier is free for typical usage
297
+ - **📊 Audit Trail**: Complete change history via CloudTrail
298
+ - **🎯 Environment Separation**: Clear dev/stg/prd isolation
299
+
300
+ #### Usage in Applications
301
+
302
+ **React Admin UI**:
303
+
304
+ ```typescript
305
+ // Read configuration from Parameter Store
306
+ const config = await getParametersByPath(`/${PROJECT_NAME}/${ENV}/app/admin-ui/`);
307
+
308
+ const cognitoConfig = {
309
+ userPoolId: config['cognito-user-pool-id'],
310
+ clientId: config['cognito-client-id'],
311
+ domain: config['cognito-domain'],
312
+ };
313
+ ```
314
+
315
+ **Lambda Functions**:
316
+
317
+ ```typescript
318
+ // Read specific parameters
319
+ const recordsApiUrl = await getParameter(`/${PROJECT_NAME}/${ENV}/app/records-api-url`);
320
+ ```
321
+
322
+ #### IAM Permissions
323
+
324
+ The Terraform module automatically creates appropriate IAM policies:
325
+
326
+ - **Admin UI**: Read access to `/app/admin-ui/*` parameters
327
+ - **Fetch Lambda**: Read access to specific required parameters
328
+ - **Minimal Permissions**: Following least privilege principle
329
+
330
+ #### Migration from Terraform Outputs
331
+
332
+ 1. **Deploy Parameter Store module** (included in v0.6.0+)
333
+ 2. **Update application code** to read from Parameter Store
334
+ 3. **Remove Terraform output dependencies**
335
+ 4. **Enjoy flexible configuration management**
336
+
337
+ ---
338
+
268
339
  ## 🔧 Shadow Configuration
269
340
 
270
341
  ### Overview
@@ -273,12 +344,12 @@ The shadow feature automatically makes all fields sortable without requiring JSO
273
344
 
274
345
  ### Environment Variables
275
346
 
276
- | Variable | Default | Description |
277
- |----------|---------|-------------|
278
- | `SHADOW_CREATED_AT_FIELD` | `createdAt` | Field name for creation timestamp |
279
- | `SHADOW_UPDATED_AT_FIELD` | `updatedAt` | Field name for update timestamp |
280
- | `SHADOW_STRING_MAX_BYTES` | `100` | Max bytes for primitive types (array/object use 2x) |
281
- | `SHADOW_NUMBER_PADDING` | `15` | Padding digits for numbers |
347
+ | Variable | Default | Description |
348
+ | ------------------------- | ----------- | --------------------------------------------------- |
349
+ | `SHADOW_CREATED_AT_FIELD` | `createdAt` | Field name for creation timestamp |
350
+ | `SHADOW_UPDATED_AT_FIELD` | `updatedAt` | Field name for update timestamp |
351
+ | `SHADOW_STRING_MAX_BYTES` | `100` | Max bytes for primitive types (array/object use 2x) |
352
+ | `SHADOW_NUMBER_PADDING` | `15` | Padding digits for numbers |
282
353
 
283
354
  ### Supported Types
284
355
 
@@ -300,7 +371,7 @@ const record = {
300
371
  viewCount: 123,
301
372
  published: true,
302
373
  tags: ['tech', 'aws'],
303
- metadata: { category: 'tech' }
374
+ metadata: { category: 'tech' },
304
375
  };
305
376
 
306
377
  // Automatically generates shadow records:
@@ -1,5 +1,5 @@
1
- // @exabugs/dynamodb-client v0.6.0
2
- // Built: 2025-12-27T03:59:32.181Z
1
+ // @exabugs/dynamodb-client v0.7.0
2
+ // Built: 2025-12-28T09:57:36.074Z
3
3
  "use strict";
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exabugs/dynamodb-client",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "DynamoDB Single-Table Client SDK with MongoDB-like API, Shadow Records, and Lambda implementation for serverless applications",
5
5
  "author": "exabugs",
6
6
  "license": "MIT",
package/terraform/main.tf CHANGED
@@ -65,6 +65,31 @@ resource "aws_iam_role_policy" "records_dynamodb" {
65
65
  })
66
66
  }
67
67
 
68
+ # カスタムインラインポリシー: KMSアクセス(Parameter Store用)
69
+ # Lambda関数がSecureString環境変数を復号化するために必要
70
+ resource "aws_iam_role_policy" "records_kms" {
71
+ name = "kms-access"
72
+ role = aws_iam_role.lambda_records.id
73
+
74
+ policy = jsonencode({
75
+ Version = "2012-10-17"
76
+ Statement = [
77
+ {
78
+ Effect = "Allow"
79
+ Action = [
80
+ "kms:Decrypt"
81
+ ]
82
+ Resource = "*"
83
+ Condition = {
84
+ StringEquals = {
85
+ "kms:ViaService" = "ssm.${var.region}.amazonaws.com"
86
+ }
87
+ }
88
+ }
89
+ ]
90
+ })
91
+ }
92
+
68
93
  # CloudWatch Logsロググループ
69
94
  resource "aws_cloudwatch_log_group" "lambda_records" {
70
95
  name = "/aws/lambda/${var.project_name}-${var.environment}-records"
@@ -127,7 +152,8 @@ resource "aws_lambda_function" "records" {
127
152
  # CloudWatch Logsへの依存関係を明示
128
153
  depends_on = [
129
154
  aws_cloudwatch_log_group.lambda_records,
130
- aws_iam_role_policy.records_dynamodb
155
+ aws_iam_role_policy.records_dynamodb,
156
+ aws_iam_role_policy.records_kms
131
157
  ]
132
158
 
133
159
  tags = {
@@ -143,7 +169,7 @@ resource "aws_lambda_function_url" "records" {
143
169
  # CORS設定
144
170
  cors {
145
171
  allow_origins = ["*"]
146
- allow_methods = ["POST"]
172
+ allow_methods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
147
173
  allow_headers = ["content-type", "authorization", "x-amz-date", "x-api-key", "x-amz-security-token"]
148
174
  expose_headers = ["content-type", "x-amzn-requestid"]
149
175
  allow_credentials = false
@@ -176,7 +202,7 @@ module "parameter_store" {
176
202
 
177
203
  # Cognito設定
178
204
  cognito_user_pool_id = var.cognito_user_pool_id
179
- cognito_admin_ui_client_id = var.cognito_client_id
205
+ cognito_admin_ui_client_id = var.cognito_admin_ui_client_id
180
206
  cognito_user_pool_domain = var.cognito_user_pool_domain
181
207
 
182
208
  # DynamoDB設定
@@ -25,17 +25,33 @@ module "parameter_store" {
25
25
  environment = "dev"
26
26
  region = "us-east-1"
27
27
 
28
- # Records Lambda設定
29
- records_function_url = "https://abc123.lambda-url.us-east-1.on.aws/"
30
- records_function_arn = "arn:aws:lambda:us-east-1:123456789012:function:my-project-dev-records"
28
+ # Records Lambda設定(必須)
29
+ records_function_url = aws_lambda_function_url.records.function_url
30
+ records_function_arn = aws_lambda_function.records.arn
31
+ }
32
+ ```
33
+
34
+ **Note**: このモジュールは外部参照用のプレースホルダーパラメータも作成します。実際の値は他のTerraformモジュール(Cognito、DynamoDB等)から設定してください。
35
+
36
+ ### プレースホルダーパラメータの更新
31
37
 
32
- # Cognito設定
33
- cognito_user_pool_id = "us-east-1_ABC123DEF"
34
- cognito_admin_ui_client_id = "abc123def456ghi789"
35
- cognito_user_pool_domain = "my-project-dev"
38
+ 他のTerraformモジュールから値を設定する例:
39
+
40
+ ```hcl
41
+ # Cognitoモジュールから
42
+ resource "aws_ssm_parameter" "cognito_user_pool_id" {
43
+ name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-user-pool-id"
44
+ type = "SecureString"
45
+ value = aws_cognito_user_pool.main.id
46
+ overwrite = true
47
+ }
36
48
 
37
- # DynamoDB設定
38
- dynamodb_table_name = "my-project-dev-records"
49
+ # DynamoDBモジュールから
50
+ resource "aws_ssm_parameter" "dynamodb_table_name" {
51
+ name = "/${var.project_name}/${var.environment}/infra/dynamodb-table-name"
52
+ type = "SecureString"
53
+ value = aws_dynamodb_table.main.name
54
+ overwrite = true
39
55
  }
40
56
  ```
41
57
 
@@ -1,59 +1,13 @@
1
1
  # Parameter Store アクセス用IAMポリシー
2
2
 
3
- # Admin UI用Parameter Store読み取りポリシー
4
- resource "aws_iam_policy" "admin_ui_parameter_read" {
5
- name = "${var.project_name}-${var.environment}-admin-ui-parameter-read"
6
- description = "Admin UI用Parameter Store読み取り権限"
3
+ # Note: 実際のプロジェクトでは、以下のようなIAMポリシーを
4
+ # 各リソース(Admin UI、Fetch Lambda等)で個別に定義してください:
7
5
 
8
- policy = jsonencode({
9
- Version = "2012-10-17"
10
- Statement = [
11
- {
12
- Effect = "Allow"
13
- Action = [
14
- "ssm:GetParameter",
15
- "ssm:GetParameters",
16
- "ssm:GetParametersByPath"
17
- ]
18
- Resource = [
19
- "arn:aws:ssm:${var.region}:*:parameter/${var.project_name}/${var.environment}/app/*"
20
- ]
21
- }
22
- ]
23
- })
6
+ # Admin UI用Parameter Store読み取りポリシー例:
7
+ # Resource: "arn:aws:ssm:region:*:parameter/{project_name}/{environment}/app/*"
24
8
 
25
- tags = {
26
- Environment = var.environment
27
- ManagedBy = "terraform"
28
- Purpose = "admin-ui-parameter-access"
29
- }
30
- }
31
-
32
- # Fetch Lambda用Parameter Store読み取りポリシー
33
- resource "aws_iam_policy" "fetch_lambda_parameter_read" {
34
- name = "${var.project_name}-${var.environment}-fetch-lambda-parameter-read"
35
- description = "Fetch Lambda用Parameter Store読み取り権限"
36
-
37
- policy = jsonencode({
38
- Version = "2012-10-17"
39
- Statement = [
40
- {
41
- Effect = "Allow"
42
- Action = [
43
- "ssm:GetParameter",
44
- "ssm:GetParameters"
45
- ]
46
- Resource = [
47
- "arn:aws:ssm:${var.region}:*:parameter/${var.project_name}/${var.environment}/app/records-api-url",
48
- "arn:aws:ssm:${var.region}:*:parameter/${var.project_name}/${var.environment}/lambda/records-function-arn"
49
- ]
50
- }
51
- ]
52
- })
53
-
54
- tags = {
55
- Environment = var.environment
56
- ManagedBy = "terraform"
57
- Purpose = "fetch-lambda-parameter-access"
58
- }
59
- }
9
+ # Fetch Lambda用Parameter Store読み取りポリシー例:
10
+ # Resource: [
11
+ # "arn:aws:ssm:region:*:parameter/{project_name}/{environment}/app/records-api-url",
12
+ # "arn:aws:ssm:region:*:parameter/{project_name}/{environment}/lambda/records-function-arn"
13
+ # ]
@@ -8,7 +8,7 @@ locals {
8
8
  # AWS管理キー(alias/aws/ssm)を使用(カスタマー管理キーは禁止)
9
9
  }
10
10
 
11
- # Records Lambda Function URL
11
+ # Records Lambda Function URL (外部参照用)
12
12
  resource "aws_ssm_parameter" "app_records_api_url" {
13
13
  name = "/${var.project_name}/${var.environment}/app/records-api-url"
14
14
  type = local.parameter_type
@@ -24,7 +24,26 @@ resource "aws_ssm_parameter" "app_records_api_url" {
24
24
  }
25
25
  }
26
26
 
27
- # Cognito User Pool ID for Admin UI
27
+ # Records Lambda Function ARN (外部参照用)
28
+ resource "aws_ssm_parameter" "lambda_records_function_arn" {
29
+ name = "/${var.project_name}/${var.environment}/lambda/records-function-arn"
30
+ type = local.parameter_type
31
+ tier = local.parameter_tier
32
+ value = var.records_function_arn
33
+
34
+ description = "Records Lambda Function ARN"
35
+
36
+ tags = {
37
+ Environment = var.environment
38
+ ManagedBy = "terraform"
39
+ Category = "lambda-info"
40
+ }
41
+ }
42
+
43
+ # 外部参照用のパラメータ(実際の値を設定)
44
+ # アプリケーション(Admin UI、Fetch Lambda等)がこれらの値を参照する
45
+
46
+ # Cognito User Pool ID (Admin UI参照用)
28
47
  resource "aws_ssm_parameter" "app_admin_ui_cognito_user_pool_id" {
29
48
  name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-user-pool-id"
30
49
  type = local.parameter_type
@@ -40,7 +59,7 @@ resource "aws_ssm_parameter" "app_admin_ui_cognito_user_pool_id" {
40
59
  }
41
60
  }
42
61
 
43
- # Cognito Client ID for Admin UI
62
+ # Cognito Client ID (Admin UI参照用)
44
63
  resource "aws_ssm_parameter" "app_admin_ui_cognito_client_id" {
45
64
  name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-client-id"
46
65
  type = local.parameter_type
@@ -56,7 +75,7 @@ resource "aws_ssm_parameter" "app_admin_ui_cognito_client_id" {
56
75
  }
57
76
  }
58
77
 
59
- # Cognito Domain for Admin UI
78
+ # Cognito Domain (Admin UI参照用)
60
79
  resource "aws_ssm_parameter" "app_admin_ui_cognito_domain" {
61
80
  name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-domain"
62
81
  type = local.parameter_type
@@ -72,7 +91,7 @@ resource "aws_ssm_parameter" "app_admin_ui_cognito_domain" {
72
91
  }
73
92
  }
74
93
 
75
- # DynamoDB Table Name
94
+ # DynamoDB Table Name (外部参照用)
76
95
  resource "aws_ssm_parameter" "infra_dynamodb_table_name" {
77
96
  name = "/${var.project_name}/${var.environment}/infra/dynamodb-table-name"
78
97
  type = local.parameter_type
@@ -87,19 +106,3 @@ resource "aws_ssm_parameter" "infra_dynamodb_table_name" {
87
106
  Category = "infra-info"
88
107
  }
89
108
  }
90
-
91
- # Records Lambda Function ARN
92
- resource "aws_ssm_parameter" "lambda_records_function_arn" {
93
- name = "/${var.project_name}/${var.environment}/lambda/records-function-arn"
94
- type = local.parameter_type
95
- tier = local.parameter_tier
96
- value = var.records_function_arn
97
-
98
- description = "Records Lambda Function ARN"
99
-
100
- tags = {
101
- Environment = var.environment
102
- ManagedBy = "terraform"
103
- Category = "lambda-info"
104
- }
105
- }
@@ -39,20 +39,5 @@ output "parameter_paths" {
39
39
  }
40
40
  }
41
41
 
42
- # IAM Policy ARNs
43
- output "iam_policy_arns" {
44
- description = "作成されたIAMポリシーのARN一覧"
45
- value = {
46
- admin_ui_parameter_read = aws_iam_policy.admin_ui_parameter_read.arn
47
- fetch_lambda_parameter_read = aws_iam_policy.fetch_lambda_parameter_read.arn
48
- }
49
- }
50
-
51
- # IAM Policy Names
52
- output "iam_policy_names" {
53
- description = "作成されたIAMポリシーの名前一覧"
54
- value = {
55
- admin_ui_parameter_read = aws_iam_policy.admin_ui_parameter_read.name
56
- fetch_lambda_parameter_read = aws_iam_policy.fetch_lambda_parameter_read.name
57
- }
58
- }
42
+ # Note: IAMポリシーは各プロジェクトで個別に定義してください
43
+ # 詳細は iam.tf のコメントを参照
@@ -20,13 +20,18 @@ variable "records_function_url" {
20
20
  type = string
21
21
  }
22
22
 
23
+ variable "records_function_arn" {
24
+ description = "Records Lambda Function ARN"
25
+ type = string
26
+ }
27
+
23
28
  variable "cognito_user_pool_id" {
24
29
  description = "Cognito User Pool ID"
25
30
  type = string
26
31
  }
27
32
 
28
33
  variable "cognito_admin_ui_client_id" {
29
- description = "Admin UI用Cognito App Client ID"
34
+ description = "Admin UI用Cognito User Pool Client ID"
30
35
  type = string
31
36
  }
32
37
 
@@ -39,8 +44,3 @@ variable "dynamodb_table_name" {
39
44
  description = "DynamoDB Table Name"
40
45
  type = string
41
46
  }
42
-
43
- variable "records_function_arn" {
44
- description = "Records Lambda Function ARN"
45
- type = string
46
- }
@@ -41,6 +41,11 @@ variable "cognito_user_pool_domain" {
41
41
  type = string
42
42
  }
43
43
 
44
+ variable "cognito_admin_ui_client_id" {
45
+ description = "Admin UI用Cognito User Pool Client ID"
46
+ type = string
47
+ }
48
+
44
49
  variable "log_retention_days" {
45
50
  description = "CloudWatch Logsの保持期間(日数)"
46
51
  type = number