@exabugs/dynamodb-client 0.1.1 → 0.1.2
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 +16 -0
- package/README.md +211 -187
- package/dist/client/Collection.d.ts +13 -6
- package/dist/client/Collection.d.ts.map +1 -1
- package/dist/client/Collection.js +1 -1
- package/dist/client/Collection.js.map +1 -1
- package/dist/client/index.iam.d.ts +1 -1
- package/dist/client/index.iam.d.ts.map +1 -1
- package/dist/client/index.iam.js.map +1 -1
- package/dist/scripts/generate-shadow-config.d.ts +16 -0
- package/dist/scripts/generate-shadow-config.d.ts.map +1 -0
- package/dist/scripts/generate-shadow-config.js +161 -0
- package/dist/scripts/generate-shadow-config.js.map +1 -0
- package/dist/server/handler.cjs +2 -2
- package/dist/shadows/generator.d.ts +14 -3
- package/dist/shadows/generator.d.ts.map +1 -1
- package/dist/shadows/generator.js +19 -0
- package/dist/shadows/generator.js.map +1 -1
- package/dist/shadows/index.d.ts +3 -2
- package/dist/shadows/index.d.ts.map +1 -1
- package/dist/shadows/index.js +1 -1
- package/dist/shadows/index.js.map +1 -1
- package/dist/shadows/schema.d.ts +62 -0
- package/dist/shadows/schema.d.ts.map +1 -0
- package/dist/shadows/schema.js +8 -0
- package/dist/shadows/schema.js.map +1 -0
- package/dist/shadows/types.d.ts +1 -5
- package/dist/shadows/types.d.ts.map +1 -1
- package/package.json +7 -4
- package/terraform/examples/advanced/README.md +0 -129
- package/terraform/examples/advanced/main.tf +0 -158
- package/terraform/examples/advanced/shadow.config.json +0 -35
- package/terraform/examples/advanced/variables.tf +0 -28
- package/terraform/examples/basic/README.md +0 -53
- package/terraform/examples/basic/main.tf +0 -99
- package/terraform/examples/basic/variables.tf +0 -17
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# Advanced Example: Multi-Environment with External Shadow Config
|
|
2
|
-
|
|
3
|
-
terraform {
|
|
4
|
-
required_version = ">= 1.5.0"
|
|
5
|
-
|
|
6
|
-
required_providers {
|
|
7
|
-
aws = {
|
|
8
|
-
source = "hashicorp/aws"
|
|
9
|
-
version = "~> 5.0"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
provider "aws" {
|
|
15
|
-
region = var.region
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
# DynamoDB Table with TTL
|
|
19
|
-
resource "aws_dynamodb_table" "main" {
|
|
20
|
-
name = "${var.project_name}-${var.environment}-records"
|
|
21
|
-
billing_mode = "PAY_PER_REQUEST"
|
|
22
|
-
hash_key = "PK"
|
|
23
|
-
range_key = "SK"
|
|
24
|
-
|
|
25
|
-
attribute {
|
|
26
|
-
name = "PK"
|
|
27
|
-
type = "S"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
attribute {
|
|
31
|
-
name = "SK"
|
|
32
|
-
type = "S"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# TTL Configuration
|
|
36
|
-
ttl {
|
|
37
|
-
attribute_name = "ttl"
|
|
38
|
-
enabled = true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# Point-in-time Recovery
|
|
42
|
-
point_in_time_recovery {
|
|
43
|
-
enabled = var.environment == "prd"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
tags = {
|
|
47
|
-
Name = "${var.project_name}-${var.environment}-records"
|
|
48
|
-
Environment = var.environment
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
# Cognito User Pool with Advanced Settings
|
|
53
|
-
resource "aws_cognito_user_pool" "main" {
|
|
54
|
-
name = "${var.project_name}-${var.environment}-users"
|
|
55
|
-
|
|
56
|
-
# Password Policy
|
|
57
|
-
password_policy {
|
|
58
|
-
minimum_length = 8
|
|
59
|
-
require_lowercase = true
|
|
60
|
-
require_numbers = true
|
|
61
|
-
require_symbols = true
|
|
62
|
-
require_uppercase = true
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
# MFA Configuration
|
|
66
|
-
mfa_configuration = var.environment == "prd" ? "REQUIRED" : "OPTIONAL"
|
|
67
|
-
|
|
68
|
-
tags = {
|
|
69
|
-
Name = "${var.project_name}-${var.environment}-users"
|
|
70
|
-
Environment = var.environment
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
# Cognito App Client
|
|
75
|
-
resource "aws_cognito_user_pool_client" "main" {
|
|
76
|
-
name = "${var.project_name}-${var.environment}-client"
|
|
77
|
-
user_pool_id = aws_cognito_user_pool.main.id
|
|
78
|
-
|
|
79
|
-
explicit_auth_flows = [
|
|
80
|
-
"ALLOW_USER_SRP_AUTH",
|
|
81
|
-
"ALLOW_REFRESH_TOKEN_AUTH"
|
|
82
|
-
]
|
|
83
|
-
|
|
84
|
-
# Token Validity
|
|
85
|
-
access_token_validity = 1 # 1 hour
|
|
86
|
-
id_token_validity = 1 # 1 hour
|
|
87
|
-
refresh_token_validity = 30 # 30 days
|
|
88
|
-
|
|
89
|
-
token_validity_units {
|
|
90
|
-
access_token = "hours"
|
|
91
|
-
id_token = "hours"
|
|
92
|
-
refresh_token = "days"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
# Records Lambda Module with External Config
|
|
97
|
-
module "lambda_records" {
|
|
98
|
-
source = "../../"
|
|
99
|
-
|
|
100
|
-
project_name = var.project_name
|
|
101
|
-
environment = var.environment
|
|
102
|
-
region = var.region
|
|
103
|
-
|
|
104
|
-
# DynamoDB
|
|
105
|
-
dynamodb_table_name = aws_dynamodb_table.main.name
|
|
106
|
-
dynamodb_table_arn = aws_dynamodb_table.main.arn
|
|
107
|
-
|
|
108
|
-
# Cognito
|
|
109
|
-
cognito_user_pool_id = aws_cognito_user_pool.main.id
|
|
110
|
-
cognito_client_id = aws_cognito_user_pool_client.main.id
|
|
111
|
-
|
|
112
|
-
# Shadow Config from External File
|
|
113
|
-
shadow_config = base64encode(file("${path.module}/shadow.config.json"))
|
|
114
|
-
|
|
115
|
-
# Logging (environment-specific)
|
|
116
|
-
log_retention_days = var.environment == "prd" ? 30 : 7
|
|
117
|
-
log_level = var.environment == "prd" ? "warn" : "debug"
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
# CloudWatch Alarm for Lambda Errors
|
|
121
|
-
resource "aws_cloudwatch_metric_alarm" "lambda_errors" {
|
|
122
|
-
alarm_name = "${var.project_name}-${var.environment}-lambda-errors"
|
|
123
|
-
comparison_operator = "GreaterThanThreshold"
|
|
124
|
-
evaluation_periods = 1
|
|
125
|
-
metric_name = "Errors"
|
|
126
|
-
namespace = "AWS/Lambda"
|
|
127
|
-
period = 300
|
|
128
|
-
statistic = "Sum"
|
|
129
|
-
threshold = 10
|
|
130
|
-
alarm_description = "Lambda function error rate is too high"
|
|
131
|
-
|
|
132
|
-
dimensions = {
|
|
133
|
-
FunctionName = module.lambda_records.function_name
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
alarm_actions = var.sns_topic_arn != "" ? [var.sns_topic_arn] : []
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
# Outputs
|
|
140
|
-
output "function_url" {
|
|
141
|
-
description = "Lambda Function URL"
|
|
142
|
-
value = module.lambda_records.function_url
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
output "function_name" {
|
|
146
|
-
description = "Lambda Function Name"
|
|
147
|
-
value = module.lambda_records.function_name
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
output "cognito_user_pool_id" {
|
|
151
|
-
description = "Cognito User Pool ID"
|
|
152
|
-
value = aws_cognito_user_pool.main.id
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
output "cognito_client_id" {
|
|
156
|
-
description = "Cognito App Client ID"
|
|
157
|
-
value = aws_cognito_user_pool_client.main.id
|
|
158
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schemaVersion": "1.0",
|
|
3
|
-
"resources": {
|
|
4
|
-
"articles": {
|
|
5
|
-
"sortDefaults": {
|
|
6
|
-
"field": "updatedAt",
|
|
7
|
-
"order": "DESC"
|
|
8
|
-
},
|
|
9
|
-
"shadows": {
|
|
10
|
-
"title": { "type": "string" },
|
|
11
|
-
"status": { "type": "string" },
|
|
12
|
-
"publishedAt": { "type": "datetime" },
|
|
13
|
-
"createdAt": { "type": "datetime" },
|
|
14
|
-
"updatedAt": { "type": "datetime" }
|
|
15
|
-
},
|
|
16
|
-
"ttl": {
|
|
17
|
-
"days": 90
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"tasks": {
|
|
21
|
-
"sortDefaults": {
|
|
22
|
-
"field": "priority",
|
|
23
|
-
"order": "DESC"
|
|
24
|
-
},
|
|
25
|
-
"shadows": {
|
|
26
|
-
"title": { "type": "string" },
|
|
27
|
-
"status": { "type": "string" },
|
|
28
|
-
"priority": { "type": "number" },
|
|
29
|
-
"dueDate": { "type": "datetime" },
|
|
30
|
-
"createdAt": { "type": "datetime" },
|
|
31
|
-
"updatedAt": { "type": "datetime" }
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
variable "project_name" {
|
|
2
|
-
description = "Project name"
|
|
3
|
-
type = string
|
|
4
|
-
default = "my-project"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
variable "environment" {
|
|
8
|
-
description = "Environment (dev/stg/prd)"
|
|
9
|
-
type = string
|
|
10
|
-
default = "dev"
|
|
11
|
-
|
|
12
|
-
validation {
|
|
13
|
-
condition = contains(["dev", "stg", "prd"], var.environment)
|
|
14
|
-
error_message = "Environment must be dev, stg, or prd."
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
variable "region" {
|
|
19
|
-
description = "AWS Region"
|
|
20
|
-
type = string
|
|
21
|
-
default = "us-east-1"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
variable "sns_topic_arn" {
|
|
25
|
-
description = "SNS Topic ARN for CloudWatch Alarms (optional)"
|
|
26
|
-
type = string
|
|
27
|
-
default = ""
|
|
28
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Basic Example
|
|
2
|
-
|
|
3
|
-
This example demonstrates a basic deployment of the DynamoDB Client Lambda function with minimal configuration.
|
|
4
|
-
|
|
5
|
-
## What This Example Creates
|
|
6
|
-
|
|
7
|
-
- DynamoDB table (Single-Table design)
|
|
8
|
-
- Cognito User Pool (for authentication)
|
|
9
|
-
- Records Lambda function with Function URL
|
|
10
|
-
- IAM roles and policies
|
|
11
|
-
- CloudWatch Logs
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
1. Initialize Terraform:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
terraform init
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
2. Review the plan:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
terraform plan
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
3. Apply the configuration:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
terraform apply
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
4. Get the Function URL:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
terraform output function_url
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Clean Up
|
|
40
|
-
|
|
41
|
-
To destroy all resources:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
terraform destroy
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Customization
|
|
48
|
-
|
|
49
|
-
You can customize the deployment by modifying `variables.tf` or passing variables:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
terraform apply -var="project_name=my-app" -var="environment=prod"
|
|
53
|
-
```
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# Basic Example: DynamoDB Client Lambda Deployment
|
|
2
|
-
|
|
3
|
-
terraform {
|
|
4
|
-
required_version = ">= 1.5.0"
|
|
5
|
-
|
|
6
|
-
required_providers {
|
|
7
|
-
aws = {
|
|
8
|
-
source = "hashicorp/aws"
|
|
9
|
-
version = "~> 5.0"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
provider "aws" {
|
|
15
|
-
region = var.region
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
# DynamoDB Table
|
|
19
|
-
resource "aws_dynamodb_table" "main" {
|
|
20
|
-
name = "${var.project_name}-${var.environment}-records"
|
|
21
|
-
billing_mode = "PAY_PER_REQUEST"
|
|
22
|
-
hash_key = "PK"
|
|
23
|
-
range_key = "SK"
|
|
24
|
-
|
|
25
|
-
attribute {
|
|
26
|
-
name = "PK"
|
|
27
|
-
type = "S"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
attribute {
|
|
31
|
-
name = "SK"
|
|
32
|
-
type = "S"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
tags = {
|
|
36
|
-
Name = "${var.project_name}-${var.environment}-records"
|
|
37
|
-
Environment = var.environment
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# Cognito User Pool
|
|
42
|
-
resource "aws_cognito_user_pool" "main" {
|
|
43
|
-
name = "${var.project_name}-${var.environment}-users"
|
|
44
|
-
|
|
45
|
-
tags = {
|
|
46
|
-
Name = "${var.project_name}-${var.environment}-users"
|
|
47
|
-
Environment = var.environment
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
# Records Lambda Module
|
|
52
|
-
module "lambda_records" {
|
|
53
|
-
source = "../../"
|
|
54
|
-
|
|
55
|
-
project_name = var.project_name
|
|
56
|
-
environment = var.environment
|
|
57
|
-
region = var.region
|
|
58
|
-
|
|
59
|
-
# DynamoDB
|
|
60
|
-
dynamodb_table_name = aws_dynamodb_table.main.name
|
|
61
|
-
dynamodb_table_arn = aws_dynamodb_table.main.arn
|
|
62
|
-
|
|
63
|
-
# Cognito
|
|
64
|
-
cognito_user_pool_id = aws_cognito_user_pool.main.id
|
|
65
|
-
|
|
66
|
-
# Shadow Config
|
|
67
|
-
shadow_config = base64encode(jsonencode({
|
|
68
|
-
"$schemaVersion" = "1.0"
|
|
69
|
-
resources = {
|
|
70
|
-
articles = {
|
|
71
|
-
sortDefaults = {
|
|
72
|
-
field = "updatedAt"
|
|
73
|
-
order = "DESC"
|
|
74
|
-
}
|
|
75
|
-
shadows = {
|
|
76
|
-
title = { type = "string" }
|
|
77
|
-
status = { type = "string" }
|
|
78
|
-
createdAt = { type = "datetime" }
|
|
79
|
-
updatedAt = { type = "datetime" }
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}))
|
|
84
|
-
|
|
85
|
-
# Logging
|
|
86
|
-
log_retention_days = 7
|
|
87
|
-
log_level = "info"
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
# Outputs
|
|
91
|
-
output "function_url" {
|
|
92
|
-
description = "Lambda Function URL"
|
|
93
|
-
value = module.lambda_records.function_url
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
output "function_name" {
|
|
97
|
-
description = "Lambda Function Name"
|
|
98
|
-
value = module.lambda_records.function_name
|
|
99
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
variable "project_name" {
|
|
2
|
-
description = "Project name"
|
|
3
|
-
type = string
|
|
4
|
-
default = "my-project"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
variable "environment" {
|
|
8
|
-
description = "Environment (dev/stg/prd)"
|
|
9
|
-
type = string
|
|
10
|
-
default = "dev"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
variable "region" {
|
|
14
|
-
description = "AWS Region"
|
|
15
|
-
type = string
|
|
16
|
-
default = "us-east-1"
|
|
17
|
-
}
|