@exabugs/dynamodb-client 0.5.0 → 0.6.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/dist/server/handler.cjs +2 -2
- package/package.json +1 -1
- package/terraform/main.tf +26 -0
- package/terraform/modules/parameter-store/README.md +113 -0
- package/terraform/modules/parameter-store/iam.tf +59 -0
- package/terraform/modules/parameter-store/main.tf +105 -0
- package/terraform/modules/parameter-store/outputs.tf +58 -0
- package/terraform/modules/parameter-store/variables.tf +46 -0
- package/terraform/variables.tf +5 -0
package/dist/server/handler.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exabugs/dynamodb-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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
|
@@ -161,3 +161,29 @@ resource "aws_lambda_permission" "function_url" {
|
|
|
161
161
|
principal = "*"
|
|
162
162
|
function_url_auth_type = "NONE"
|
|
163
163
|
}
|
|
164
|
+
# Parameter Store モジュール
|
|
165
|
+
module "parameter_store" {
|
|
166
|
+
source = "./modules/parameter-store"
|
|
167
|
+
|
|
168
|
+
# 基本設定
|
|
169
|
+
project_name = var.project_name
|
|
170
|
+
environment = var.environment
|
|
171
|
+
region = var.region
|
|
172
|
+
|
|
173
|
+
# Records Lambda設定
|
|
174
|
+
records_function_url = aws_lambda_function_url.records.function_url
|
|
175
|
+
records_function_arn = aws_lambda_function.records.arn
|
|
176
|
+
|
|
177
|
+
# Cognito設定
|
|
178
|
+
cognito_user_pool_id = var.cognito_user_pool_id
|
|
179
|
+
cognito_admin_ui_client_id = var.cognito_client_id
|
|
180
|
+
cognito_user_pool_domain = var.cognito_user_pool_domain
|
|
181
|
+
|
|
182
|
+
# DynamoDB設定
|
|
183
|
+
dynamodb_table_name = var.dynamodb_table_name
|
|
184
|
+
|
|
185
|
+
depends_on = [
|
|
186
|
+
aws_lambda_function.records,
|
|
187
|
+
aws_lambda_function_url.records
|
|
188
|
+
]
|
|
189
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Parameter Store Terraform Module
|
|
2
|
+
|
|
3
|
+
AWS Parameter Storeを使用してアプリケーション設定を管理するTerraformモジュールです。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
このモジュールは、DynamoDB Clientライブラリを使用するアプリケーションの設定情報をAWS Parameter Storeで管理します。
|
|
8
|
+
|
|
9
|
+
## 特徴
|
|
10
|
+
|
|
11
|
+
- **Standard階層**: 標準スループット(1,000 TPS以下)では無料
|
|
12
|
+
- **SecureString**: すべてのパラメータをKMS暗号化で保存
|
|
13
|
+
- **AWS管理キー**: `alias/aws/ssm`を使用(月額料金なし)
|
|
14
|
+
- **階層構造**: `/{project_name}/{environment}/`で環境別に管理
|
|
15
|
+
- **IAMポリシー**: Admin UIとFetch Lambda用のアクセス権限を提供
|
|
16
|
+
|
|
17
|
+
## 使用方法
|
|
18
|
+
|
|
19
|
+
```hcl
|
|
20
|
+
module "parameter_store" {
|
|
21
|
+
source = "./modules/parameter-store"
|
|
22
|
+
|
|
23
|
+
# 基本設定
|
|
24
|
+
project_name = "my-project"
|
|
25
|
+
environment = "dev"
|
|
26
|
+
region = "us-east-1"
|
|
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"
|
|
31
|
+
|
|
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"
|
|
36
|
+
|
|
37
|
+
# DynamoDB設定
|
|
38
|
+
dynamodb_table_name = "my-project-dev-records"
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## パラメータ構造
|
|
43
|
+
|
|
44
|
+
### アプリケーション設定 (`/app/`)
|
|
45
|
+
|
|
46
|
+
- `/{project_name}/{environment}/app/records-api-url`
|
|
47
|
+
- `/{project_name}/{environment}/app/admin-ui/cognito-user-pool-id`
|
|
48
|
+
- `/{project_name}/{environment}/app/admin-ui/cognito-client-id`
|
|
49
|
+
- `/{project_name}/{environment}/app/admin-ui/cognito-domain`
|
|
50
|
+
|
|
51
|
+
### インフラ情報 (`/infra/`)
|
|
52
|
+
|
|
53
|
+
- `/{project_name}/{environment}/infra/dynamodb-table-name`
|
|
54
|
+
|
|
55
|
+
### Lambda情報 (`/lambda/`)
|
|
56
|
+
|
|
57
|
+
- `/{project_name}/{environment}/lambda/records-function-arn`
|
|
58
|
+
|
|
59
|
+
## IAMポリシー
|
|
60
|
+
|
|
61
|
+
### Admin UI用ポリシー
|
|
62
|
+
|
|
63
|
+
Admin UIが必要とするパラメータへの読み取り権限:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"Effect": "Allow",
|
|
68
|
+
"Action": ["ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath"],
|
|
69
|
+
"Resource": ["arn:aws:ssm:region:*:parameter/{project_name}/{environment}/app/*"]
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Fetch Lambda用ポリシー
|
|
74
|
+
|
|
75
|
+
Fetch Lambdaが必要とする特定パラメータへの読み取り権限:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"Effect": "Allow",
|
|
80
|
+
"Action": ["ssm:GetParameter", "ssm:GetParameters"],
|
|
81
|
+
"Resource": [
|
|
82
|
+
"arn:aws:ssm:region:*:parameter/{project_name}/{environment}/app/records-api-url",
|
|
83
|
+
"arn:aws:ssm:region:*:parameter/{project_name}/{environment}/lambda/records-function-arn"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 出力
|
|
89
|
+
|
|
90
|
+
- `parameter_arns`: 作成されたパラメータのARN一覧
|
|
91
|
+
- `parameter_names`: 作成されたパラメータの名前一覧
|
|
92
|
+
- `parameter_paths`: 作成されたパラメータのパス一覧
|
|
93
|
+
- `iam_policy_arns`: 作成されたIAMポリシーのARN一覧
|
|
94
|
+
- `iam_policy_names`: 作成されたIAMポリシーの名前一覧
|
|
95
|
+
|
|
96
|
+
## コスト
|
|
97
|
+
|
|
98
|
+
- **Parameter Store Standard**: 標準スループット(1,000 TPS以下)では無料
|
|
99
|
+
- **AWS管理キー**: 無料(カスタマー管理キーと異なり月額料金なし)
|
|
100
|
+
- **実質的なコスト**: 通常の使用では完全に無料
|
|
101
|
+
|
|
102
|
+
## セキュリティ
|
|
103
|
+
|
|
104
|
+
- すべてのパラメータがKMS暗号化(SecureString)
|
|
105
|
+
- IAMによる細かい権限管理
|
|
106
|
+
- CloudTrailで完全な操作追跡
|
|
107
|
+
- 最小権限の原則に基づくアクセス制御
|
|
108
|
+
|
|
109
|
+
## 要件
|
|
110
|
+
|
|
111
|
+
- Terraform >= 1.0
|
|
112
|
+
- AWS Provider >= 4.0
|
|
113
|
+
- 適切なAWS認証情報の設定
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Parameter Store アクセス用IAMポリシー
|
|
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読み取り権限"
|
|
7
|
+
|
|
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
|
+
})
|
|
24
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Parameter Store モジュール
|
|
2
|
+
# AWS Parameter Store を使用してアプリケーション設定を管理
|
|
3
|
+
|
|
4
|
+
# Parameter Store設定の共通変数
|
|
5
|
+
locals {
|
|
6
|
+
parameter_tier = "Standard" # Standard階層を使用(実質無料)
|
|
7
|
+
parameter_type = "SecureString" # すべてSecureStringで統一
|
|
8
|
+
# AWS管理キー(alias/aws/ssm)を使用(カスタマー管理キーは禁止)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
# Records Lambda Function URL
|
|
12
|
+
resource "aws_ssm_parameter" "app_records_api_url" {
|
|
13
|
+
name = "/${var.project_name}/${var.environment}/app/records-api-url"
|
|
14
|
+
type = local.parameter_type
|
|
15
|
+
tier = local.parameter_tier
|
|
16
|
+
value = var.records_function_url
|
|
17
|
+
|
|
18
|
+
description = "Records Lambda Function URL"
|
|
19
|
+
|
|
20
|
+
tags = {
|
|
21
|
+
Environment = var.environment
|
|
22
|
+
ManagedBy = "terraform"
|
|
23
|
+
Category = "app-config"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Cognito User Pool ID for Admin UI
|
|
28
|
+
resource "aws_ssm_parameter" "app_admin_ui_cognito_user_pool_id" {
|
|
29
|
+
name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-user-pool-id"
|
|
30
|
+
type = local.parameter_type
|
|
31
|
+
tier = local.parameter_tier
|
|
32
|
+
value = var.cognito_user_pool_id
|
|
33
|
+
|
|
34
|
+
description = "Cognito User Pool ID for Admin UI"
|
|
35
|
+
|
|
36
|
+
tags = {
|
|
37
|
+
Environment = var.environment
|
|
38
|
+
ManagedBy = "terraform"
|
|
39
|
+
Category = "app-config"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Cognito Client ID for Admin UI
|
|
44
|
+
resource "aws_ssm_parameter" "app_admin_ui_cognito_client_id" {
|
|
45
|
+
name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-client-id"
|
|
46
|
+
type = local.parameter_type
|
|
47
|
+
tier = local.parameter_tier
|
|
48
|
+
value = var.cognito_admin_ui_client_id
|
|
49
|
+
|
|
50
|
+
description = "Cognito Client ID for Admin UI"
|
|
51
|
+
|
|
52
|
+
tags = {
|
|
53
|
+
Environment = var.environment
|
|
54
|
+
ManagedBy = "terraform"
|
|
55
|
+
Category = "app-config"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Cognito Domain for Admin UI
|
|
60
|
+
resource "aws_ssm_parameter" "app_admin_ui_cognito_domain" {
|
|
61
|
+
name = "/${var.project_name}/${var.environment}/app/admin-ui/cognito-domain"
|
|
62
|
+
type = local.parameter_type
|
|
63
|
+
tier = local.parameter_tier
|
|
64
|
+
value = "${var.cognito_user_pool_domain}.auth.${var.region}.amazoncognito.com"
|
|
65
|
+
|
|
66
|
+
description = "Cognito Domain for Admin UI"
|
|
67
|
+
|
|
68
|
+
tags = {
|
|
69
|
+
Environment = var.environment
|
|
70
|
+
ManagedBy = "terraform"
|
|
71
|
+
Category = "app-config"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# DynamoDB Table Name
|
|
76
|
+
resource "aws_ssm_parameter" "infra_dynamodb_table_name" {
|
|
77
|
+
name = "/${var.project_name}/${var.environment}/infra/dynamodb-table-name"
|
|
78
|
+
type = local.parameter_type
|
|
79
|
+
tier = local.parameter_tier
|
|
80
|
+
value = var.dynamodb_table_name
|
|
81
|
+
|
|
82
|
+
description = "DynamoDB Table Name"
|
|
83
|
+
|
|
84
|
+
tags = {
|
|
85
|
+
Environment = var.environment
|
|
86
|
+
ManagedBy = "terraform"
|
|
87
|
+
Category = "infra-info"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Parameter Store モジュール出力
|
|
2
|
+
|
|
3
|
+
# Parameter Store ARNs
|
|
4
|
+
output "parameter_arns" {
|
|
5
|
+
description = "作成されたParameter StoreパラメータのARN一覧"
|
|
6
|
+
value = {
|
|
7
|
+
records_api_url = aws_ssm_parameter.app_records_api_url.arn
|
|
8
|
+
cognito_user_pool_id = aws_ssm_parameter.app_admin_ui_cognito_user_pool_id.arn
|
|
9
|
+
cognito_client_id = aws_ssm_parameter.app_admin_ui_cognito_client_id.arn
|
|
10
|
+
cognito_domain = aws_ssm_parameter.app_admin_ui_cognito_domain.arn
|
|
11
|
+
dynamodb_table_name = aws_ssm_parameter.infra_dynamodb_table_name.arn
|
|
12
|
+
records_function_arn = aws_ssm_parameter.lambda_records_function_arn.arn
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# Parameter Store Names
|
|
17
|
+
output "parameter_names" {
|
|
18
|
+
description = "作成されたParameter Storeパラメータの名前一覧"
|
|
19
|
+
value = {
|
|
20
|
+
records_api_url = aws_ssm_parameter.app_records_api_url.name
|
|
21
|
+
cognito_user_pool_id = aws_ssm_parameter.app_admin_ui_cognito_user_pool_id.name
|
|
22
|
+
cognito_client_id = aws_ssm_parameter.app_admin_ui_cognito_client_id.name
|
|
23
|
+
cognito_domain = aws_ssm_parameter.app_admin_ui_cognito_domain.name
|
|
24
|
+
dynamodb_table_name = aws_ssm_parameter.infra_dynamodb_table_name.name
|
|
25
|
+
records_function_arn = aws_ssm_parameter.lambda_records_function_arn.name
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# Parameter Store Paths (same as names)
|
|
30
|
+
output "parameter_paths" {
|
|
31
|
+
description = "作成されたParameter Storeパラメータのパス一覧"
|
|
32
|
+
value = {
|
|
33
|
+
records_api_url = aws_ssm_parameter.app_records_api_url.name
|
|
34
|
+
cognito_user_pool_id = aws_ssm_parameter.app_admin_ui_cognito_user_pool_id.name
|
|
35
|
+
cognito_client_id = aws_ssm_parameter.app_admin_ui_cognito_client_id.name
|
|
36
|
+
cognito_domain = aws_ssm_parameter.app_admin_ui_cognito_domain.name
|
|
37
|
+
dynamodb_table_name = aws_ssm_parameter.infra_dynamodb_table_name.name
|
|
38
|
+
records_function_arn = aws_ssm_parameter.lambda_records_function_arn.name
|
|
39
|
+
}
|
|
40
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Parameter Store モジュール変数定義
|
|
2
|
+
|
|
3
|
+
variable "project_name" {
|
|
4
|
+
description = "プロジェクト名"
|
|
5
|
+
type = string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
variable "environment" {
|
|
9
|
+
description = "環境識別子(dev, stg, prd)"
|
|
10
|
+
type = string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
variable "region" {
|
|
14
|
+
description = "AWSリージョン"
|
|
15
|
+
type = string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
variable "records_function_url" {
|
|
19
|
+
description = "Records Lambda Function URL"
|
|
20
|
+
type = string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
variable "cognito_user_pool_id" {
|
|
24
|
+
description = "Cognito User Pool ID"
|
|
25
|
+
type = string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
variable "cognito_admin_ui_client_id" {
|
|
29
|
+
description = "Admin UI用Cognito App Client ID"
|
|
30
|
+
type = string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
variable "cognito_user_pool_domain" {
|
|
34
|
+
description = "Cognito User Pool Domain"
|
|
35
|
+
type = string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
variable "dynamodb_table_name" {
|
|
39
|
+
description = "DynamoDB Table Name"
|
|
40
|
+
type = string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
variable "records_function_arn" {
|
|
44
|
+
description = "Records Lambda Function ARN"
|
|
45
|
+
type = string
|
|
46
|
+
}
|
package/terraform/variables.tf
CHANGED
|
@@ -36,6 +36,11 @@ variable "cognito_client_id" {
|
|
|
36
36
|
default = ""
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
variable "cognito_user_pool_domain" {
|
|
40
|
+
description = "Cognito User Pool Domain"
|
|
41
|
+
type = string
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
variable "log_retention_days" {
|
|
40
45
|
description = "CloudWatch Logsの保持期間(日数)"
|
|
41
46
|
type = number
|