@mbc-cqrs-serverless/cli 1.2.1 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbc-cqrs-serverless/cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
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": "89a28b1fdcd20b731a0c02be92a2194634451209"
61
+ "gitHead": "1a47757dc1d91b650d413d1e414895abf0af8dc9"
62
62
  }
@@ -16,6 +16,17 @@ export type DistributedMapS3Parameter =
16
16
  readonly Key: JsonPath | string
17
17
  }
18
18
 
19
+ /** ResultWriter uses Bucket + Prefix (not Key). See distributed Map ResultWriter. */
20
+ export type DistributedMapResultWriterParameters =
21
+ | {
22
+ readonly 'Bucket.$': string
23
+ readonly 'Prefix.$': string
24
+ }
25
+ | {
26
+ readonly Bucket: JsonPath | string
27
+ readonly Prefix: JsonPath | string
28
+ }
29
+
19
30
  export interface DistributedMapItemReader {
20
31
  readonly Resource:
21
32
  | 'arn:aws:states:::s3:getObject'
@@ -31,7 +42,7 @@ export interface DistributedMapItemReader {
31
42
 
32
43
  export interface DistributedMapResultWriter {
33
44
  readonly Resource: 'arn:aws:states:::s3:putObject'
34
- readonly Parameters: DistributedMapS3Parameter
45
+ readonly Parameters: DistributedMapResultWriterParameters
35
46
  }
36
47
 
37
48
  export interface DistributedMapItemBatcher {
@@ -402,6 +402,7 @@ export class InfraStack extends cdk.Stack {
402
402
  DATABASE_URL: `postgresql://${props.config.rds.accountSsmKey}@${props.config.rds.endpoint}/${props.config.rds.dbName}?schema=public`,
403
403
  S3_PUBLIC_BUCKET_NAME: publicBucket.bucketName,
404
404
  FRONT_BASE_URL: props.config.frontBaseUrl,
405
+ IMPORT_QUEUE_URL: importActionSqs.queueUrl,
405
406
  }
406
407
  const lambdaApi = new cdk.aws_lambda.Function(this, 'lambda-api', {
407
408
  vpc,
@@ -895,22 +896,23 @@ export class InfraStack extends cdk.Stack {
895
896
  },
896
897
  )
897
898
 
898
- const finalizeParentJobInvoke = new cdk.aws_stepfunctions_tasks.LambdaInvoke(
899
- this,
900
- 'finalize_parent_job',
901
- {
902
- lambdaFunction: lambdaApi,
903
- payload: cdk.aws_stepfunctions.TaskInput.fromObject({
904
- 'input.$': '$',
905
- 'context.$': '$$',
906
- }),
907
- stateName: 'finalize_parent_job',
908
- outputPath: '$.Payload[0][0]',
909
- integrationPattern:
910
- cdk.aws_stepfunctions.IntegrationPattern.REQUEST_RESPONSE,
911
- retryOnServiceExceptions: false,
912
- },
913
- )
899
+ const finalizeParentJobInvoke =
900
+ new cdk.aws_stepfunctions_tasks.LambdaInvoke(
901
+ this,
902
+ 'finalize_parent_job',
903
+ {
904
+ lambdaFunction: lambdaApi,
905
+ payload: cdk.aws_stepfunctions.TaskInput.fromObject({
906
+ 'input.$': '$',
907
+ 'context.$': '$$',
908
+ }),
909
+ stateName: 'finalize_parent_job',
910
+ outputPath: '$.Payload[0][0]',
911
+ integrationPattern:
912
+ cdk.aws_stepfunctions.IntegrationPattern.REQUEST_RESPONSE,
913
+ retryOnServiceExceptions: false,
914
+ },
915
+ )
914
916
  finalizeParentJobInvoke.addRetry({
915
917
  errors: [
916
918
  'Lambda.ServiceException',
@@ -921,11 +923,12 @@ export class InfraStack extends cdk.Stack {
921
923
  maxAttempts: 5,
922
924
  backoffRate: 2,
923
925
  })
924
- const finalizeParentJobState = finalizeParentJobInvoke.next(importCsvSuccess)
926
+ const finalizeParentJobState =
927
+ finalizeParentJobInvoke.next(importCsvSuccess)
925
928
 
926
929
  const sfnImportCsvDefinition = new DistributedMap(this, 'import-csv', {
927
930
  maxConcurrency: 50,
928
- resultPath: '$.processingResults',
931
+ resultPath: '$.mapOutput', // Captures the MapRunArn and ResultWriterDetails
929
932
  })
930
933
  .setLabel('import-csv')
931
934
  .setItemReader({
@@ -939,18 +942,32 @@ export class InfraStack extends cdk.Stack {
939
942
  'Key.$': '$.key',
940
943
  },
941
944
  })
942
- // For ImportPublishMode.SYNC tables, keep MaxItemsPerBatch low enough that sequential
943
- // publishSync per row stays within the Lambda timeout (see import package import-publish.ts).
944
945
  .setItemBatcher({
945
946
  MaxItemsPerBatch: 100,
946
947
  BatchInput: {
947
948
  'Attributes.$': '$',
948
949
  },
949
950
  })
951
+ .setResultWriter({
952
+ Resource: 'arn:aws:states:::s3:putObject',
953
+ Parameters: {
954
+ // Replace this with your actual CDK bucket reference (e.g., props.bucket.bucketName)
955
+ Bucket: 'your-import-bucket-name',
956
+ Prefix: 'sfn-results/import-csv',
957
+ },
958
+ })
950
959
  .itemProcessor(csvRowsHandlerState, {
951
- executionType: cdk.aws_stepfunctions.ProcessorType.EXPRESS,
960
+ executionType: aws_stepfunctions.ProcessorType.STANDARD,
952
961
  })
953
- .next(finalizeParentJobState)
962
+
963
+ // Catch ALL Map state errors and route them to finalizeParentJobState
964
+ sfnImportCsvDefinition.addCatch(finalizeParentJobState, {
965
+ errors: ['States.ALL'],
966
+ resultPath: '$.errorOutput',
967
+ })
968
+
969
+ // Normal successful flow
970
+ sfnImportCsvDefinition.next(finalizeParentJobState)
954
971
 
955
972
  const sfnImportCsvLogGroup = new cdk.aws_logs.LogGroup(
956
973
  this,
@@ -1081,6 +1098,7 @@ export class InfraStack extends cdk.Stack {
1081
1098
  taskSqs.grantSendMessages(lambdaApi)
1082
1099
  notifySqs.grantSendMessages(lambdaApi)
1083
1100
  appSyncApi.grantMutation(lambdaApi)
1101
+ importActionSqs.grantSendMessages(lambdaApi)
1084
1102
 
1085
1103
  // Define an IAM policy for full DynamoDB access
1086
1104
  const dynamoDbTablePrefixArn = cdk.Arn.format({