@mbc-cqrs-serverless/cli 1.3.3 → 1.3.4
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/index.js +1 -1
- package/dist/utils/local-binaries.js +1 -1
- package/package.json +2 -2
- package/templates/.env.local +6 -2
- package/templates/infra/config/type.ts +25 -0
- package/templates/infra/libs/infra-stack.ts +97 -1
- package/templates/infra/test/__snapshots__/infra.test.ts.snap +1 -1
- package/templates/infra-local/appsync-simulator/package-lock.json +1198 -696
- package/templates/infra-local/appsync-simulator/package.json +4 -1
- package/templates/infra-local/cognito-local/package-lock.json +297 -240
- package/templates/infra-local/cognito-local/package.json +2 -1
- package/templates/package-lock.json +8527 -3164
- package/templates/package.json +35 -13
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ async function bootstrap() {
|
|
|
11
11
|
const program = new commander_1.Command();
|
|
12
12
|
program
|
|
13
13
|
.version(
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
15
15
|
require('../package.json').version, '-v, --version', 'Output the current version.')
|
|
16
16
|
.usage('<command> [options]')
|
|
17
17
|
.helpOption('-h, --help', 'Output usage information.');
|
|
@@ -14,7 +14,7 @@ function localBinExists() {
|
|
|
14
14
|
return (0, fs_1.existsSync)((0, path_1.join)(...localBinPathSegments));
|
|
15
15
|
}
|
|
16
16
|
function loadLocalBinCommandLoader() {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
18
18
|
const commandLoader = require(path_1.posix.join(...localBinPathSegments, 'dist', 'commands'));
|
|
19
19
|
return commandLoader;
|
|
20
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbc-cqrs-serverless/cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "a CLI to get started with MBC CQRS serverless framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mbc",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"@faker-js/faker": "^8.3.1",
|
|
59
59
|
"copyfiles": "^2.4.1"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e5b2e10fe73ebd89bf26b23942752d4ebe79388e"
|
|
62
62
|
}
|
package/templates/.env.local
CHANGED
|
@@ -48,8 +48,12 @@ LOCAL_DDB_ADMIN_PORT=8001
|
|
|
48
48
|
# DynamoDB endpoint, useful for local development
|
|
49
49
|
DYNAMODB_ENDPOINT=http://localhost:${LOCAL_DYNAMODB_PORT:-8000}
|
|
50
50
|
DYNAMODB_REGION=ap-northeast-1
|
|
51
|
-
#
|
|
52
|
-
|
|
51
|
+
# Max size (bytes) for `attributes` before S3 offload.
|
|
52
|
+
# Must account for Step Functions 256 KB payload limit: the SFN state passes
|
|
53
|
+
# the DynamoDB event twice (input + context.Execution.Input), so the safe
|
|
54
|
+
# limit is ~(256 KB - overhead) / 2 ≈ 110 KB. Default: 100 KB.
|
|
55
|
+
# DynamoDB item limit is 400 KB — do NOT use that as the reference.
|
|
56
|
+
ATTRIBUTE_LIMIT_SIZE=102400
|
|
53
57
|
# S3 endpoint, useful for local development
|
|
54
58
|
S3_ENDPOINT=http://localhost:${LOCAL_S3_PORT:-4566}
|
|
55
59
|
S3_REGION=ap-northeast-1
|
|
@@ -10,8 +10,33 @@ export type Config = {
|
|
|
10
10
|
domain: {
|
|
11
11
|
http: string
|
|
12
12
|
appsync: string
|
|
13
|
+
appsyncEvents?: string // optional: custom domain for AppSync Events API
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
appsyncEvents?: {
|
|
17
|
+
/** Set true to create the AppSync Events API and inject env vars into Lambda/ECS */
|
|
18
|
+
enabled: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Channel namespace name — must be a pre-registered name in the AppSync Event API.
|
|
21
|
+
* Becomes segment 1 of every channel path: /{namespace}/{tenantCode}/{table}/{action}/{id}
|
|
22
|
+
* Defaults to 'default'.
|
|
23
|
+
*/
|
|
24
|
+
namespace: string
|
|
25
|
+
/** API key TTL in days. Defaults to 365. */
|
|
26
|
+
apiKeyExpireDays?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Value injected as NOTIFICATION_TRANSPORTS env var into Lambda/ECS.
|
|
31
|
+
* Controls which transports NotificationEventHandler uses.
|
|
32
|
+
* Examples:
|
|
33
|
+
* 'appsync-event' — Events API only
|
|
34
|
+
* 'appsync-graphql' — GraphQL API only
|
|
35
|
+
* 'appsync-graphql,appsync-event' — dual-publish (migration mode)
|
|
36
|
+
* Defaults to 'appsync-event' when appsyncEvents is enabled.
|
|
37
|
+
*/
|
|
38
|
+
notificationTransports?: string
|
|
39
|
+
|
|
15
40
|
// existing resources
|
|
16
41
|
userPoolId?: string
|
|
17
42
|
|
|
@@ -249,6 +249,76 @@ export class InfraStack extends cdk.Stack {
|
|
|
249
249
|
this.graphqlApiKey = new cdk.CfnOutput(this, 'GraphQLAPIKey', {
|
|
250
250
|
value: appSyncApi.apiKey || '',
|
|
251
251
|
})
|
|
252
|
+
|
|
253
|
+
// AppSync Events API (HTTP pub/sub, schema-free)
|
|
254
|
+
// Uses L2 EventApi so that ChannelNamespace can set explicit publishAuthModeTypes
|
|
255
|
+
// and subscribeAuthModeTypes — without these the namespace has no effective
|
|
256
|
+
// authorization and Lambda publish calls receive 401.
|
|
257
|
+
let appSyncEventsApi: cdk.aws_appsync.EventApi | undefined
|
|
258
|
+
if (props.config.appsyncEvents?.enabled) {
|
|
259
|
+
const expireDays = props.config.appsyncEvents.apiKeyExpireDays ?? 365
|
|
260
|
+
|
|
261
|
+
appSyncEventsApi = new cdk.aws_appsync.EventApi(this, 'events-api', {
|
|
262
|
+
apiName: prefix + 'events',
|
|
263
|
+
authorizationConfig: {
|
|
264
|
+
authProviders: [
|
|
265
|
+
{
|
|
266
|
+
authorizationType: cdk.aws_appsync.AppSyncAuthorizationType.IAM,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
authorizationType:
|
|
270
|
+
cdk.aws_appsync.AppSyncAuthorizationType.API_KEY,
|
|
271
|
+
apiKeyConfig: {
|
|
272
|
+
expires: cdk.Expiration.after(cdk.Duration.days(expireDays)),
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
// API-level defaults — overridden per-namespace below
|
|
277
|
+
connectionAuthModeTypes: [
|
|
278
|
+
cdk.aws_appsync.AppSyncAuthorizationType.API_KEY,
|
|
279
|
+
],
|
|
280
|
+
defaultPublishAuthModeTypes: [
|
|
281
|
+
cdk.aws_appsync.AppSyncAuthorizationType.IAM,
|
|
282
|
+
],
|
|
283
|
+
defaultSubscribeAuthModeTypes: [
|
|
284
|
+
cdk.aws_appsync.AppSyncAuthorizationType.API_KEY,
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
// Namespace — explicitly sets auth per operation so it is never left
|
|
290
|
+
// without authorization (which caused the 401).
|
|
291
|
+
// publish = AWS_IAM → Lambda signs with its execution role
|
|
292
|
+
// subscribe = API_KEY → browser clients pass x-api-key header
|
|
293
|
+
new cdk.aws_appsync.ChannelNamespace(this, 'events-namespace', {
|
|
294
|
+
api: appSyncEventsApi,
|
|
295
|
+
channelNamespaceName: props.config.appsyncEvents.namespace ?? 'default',
|
|
296
|
+
authorizationConfig: {
|
|
297
|
+
publishAuthModeTypes: [cdk.aws_appsync.AppSyncAuthorizationType.IAM],
|
|
298
|
+
subscribeAuthModeTypes: [
|
|
299
|
+
cdk.aws_appsync.AppSyncAuthorizationType.API_KEY,
|
|
300
|
+
],
|
|
301
|
+
},
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
// Outputs
|
|
305
|
+
new cdk.CfnOutput(this, 'AppSyncEventsHttpEndpoint', {
|
|
306
|
+
value: `https://${appSyncEventsApi.httpDns}/event`,
|
|
307
|
+
description:
|
|
308
|
+
'AppSync Events HTTP endpoint — APPSYNC_EVENTS_ENDPOINT env var',
|
|
309
|
+
})
|
|
310
|
+
new cdk.CfnOutput(this, 'AppSyncEventsRealtimeEndpoint', {
|
|
311
|
+
value: `wss://${appSyncEventsApi.realtimeDns}/event/realtime`,
|
|
312
|
+
description:
|
|
313
|
+
'AppSync Events WebSocket endpoint for client subscriptions',
|
|
314
|
+
})
|
|
315
|
+
new cdk.CfnOutput(this, 'AppSyncEventsNamespace', {
|
|
316
|
+
value: props.config.appsyncEvents.namespace ?? 'default',
|
|
317
|
+
description:
|
|
318
|
+
'AppSync Events namespace — APPSYNC_EVENTS_NAMESPACE env var',
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
|
|
252
322
|
// S3
|
|
253
323
|
const ddbBucket = new cdk.aws_s3.Bucket(this, 'ddb-attributes', {
|
|
254
324
|
bucketName: prefix + 'ddb-attributes', // Globally unique bucket name
|
|
@@ -389,7 +459,12 @@ export class InfraStack extends cdk.Stack {
|
|
|
389
459
|
APP_NAME: name,
|
|
390
460
|
LOG_LEVEL: props.config.logLevel?.level || 'info',
|
|
391
461
|
EVENT_SOURCE_DISABLED: 'false',
|
|
392
|
-
|
|
462
|
+
// Max size (bytes) for `attributes` before S3 offload.
|
|
463
|
+
// Must account for Step Functions 256 KB payload limit: the SFN state passes
|
|
464
|
+
// the DynamoDB event twice (input + context.Execution.Input), so the safe
|
|
465
|
+
// limit is ~(256 KB - overhead) / 2 ≈ 110 KB. Default: 100 KB.
|
|
466
|
+
// DynamoDB item limit is 400 KB — do NOT use that as the reference.
|
|
467
|
+
ATTRIBUTE_LIMIT_SIZE: '102400',
|
|
393
468
|
S3_BUCKET_NAME: ddbBucket.bucketName,
|
|
394
469
|
SFN_COMMAND_ARN: commandSfnArn,
|
|
395
470
|
SFN_TASK_ARN: taskSfnArn,
|
|
@@ -398,6 +473,16 @@ export class InfraStack extends cdk.Stack {
|
|
|
398
473
|
SNS_ALARM_TOPIC_ARN: alarmSns.topicArn,
|
|
399
474
|
COGNITO_USER_POOL_ID: userPool.userPoolId,
|
|
400
475
|
APPSYNC_ENDPOINT: appSyncApi.graphqlUrl,
|
|
476
|
+
// AppSync Events — only injected when feature is enabled
|
|
477
|
+
...(props.config.appsyncEvents?.enabled && appSyncEventsApi
|
|
478
|
+
? {
|
|
479
|
+
NOTIFICATION_TRANSPORTS:
|
|
480
|
+
props.config.notificationTransports ?? 'appsync-event',
|
|
481
|
+
APPSYNC_EVENTS_ENDPOINT: `https://${appSyncEventsApi.httpDns}/event`,
|
|
482
|
+
APPSYNC_EVENTS_NAMESPACE:
|
|
483
|
+
props.config.appsyncEvents.namespace ?? 'default',
|
|
484
|
+
}
|
|
485
|
+
: {}),
|
|
401
486
|
SES_FROM_EMAIL: props.config.fromEmailAddress,
|
|
402
487
|
DATABASE_URL: `postgresql://${props.config.rds.accountSsmKey}@${props.config.rds.endpoint}/${props.config.rds.dbName}?schema=public`,
|
|
403
488
|
S3_PUBLIC_BUCKET_NAME: publicBucket.bucketName,
|
|
@@ -645,6 +730,14 @@ export class InfraStack extends cdk.Stack {
|
|
|
645
730
|
domainName: httpDistribution.distributionDomainName,
|
|
646
731
|
})
|
|
647
732
|
|
|
733
|
+
if (props.config.domain.appsyncEvents && appSyncEventsApi) {
|
|
734
|
+
new cdk.aws_route53.CnameRecord(this, 'AppSyncEventsCnameRecord', {
|
|
735
|
+
zone: hostedZone,
|
|
736
|
+
recordName: props.config.domain.appsyncEvents,
|
|
737
|
+
domainName: appSyncEventsApi.httpDns,
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
|
|
648
741
|
this.httpDistributionDomain = new cdk.CfnOutput(
|
|
649
742
|
this,
|
|
650
743
|
'http-distribution-domain',
|
|
@@ -1100,6 +1193,8 @@ export class InfraStack extends cdk.Stack {
|
|
|
1100
1193
|
appSyncApi.grantMutation(lambdaApi)
|
|
1101
1194
|
importActionSqs.grantSendMessages(lambdaApi)
|
|
1102
1195
|
|
|
1196
|
+
appSyncEventsApi?.grantPublish(lambdaApi)
|
|
1197
|
+
|
|
1103
1198
|
// Define an IAM policy for full DynamoDB access
|
|
1104
1199
|
const dynamoDbTablePrefixArn = cdk.Arn.format({
|
|
1105
1200
|
partition: 'aws',
|
|
@@ -1231,6 +1326,7 @@ export class InfraStack extends cdk.Stack {
|
|
|
1231
1326
|
statements: [ssmPolicy],
|
|
1232
1327
|
}),
|
|
1233
1328
|
)
|
|
1329
|
+
appSyncEventsApi?.grantPublish(taskRole)
|
|
1234
1330
|
}
|
|
1235
1331
|
}
|
|
1236
1332
|
}
|