diff --git a/.projen/deps.json b/.projen/deps.json index 70ba1fbf..0d7fbeae 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -2,22 +2,22 @@ "dependencies": [ { "name": "@aws-cdk/aws-glue-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "build" }, { "name": "@aws-cdk/aws-kinesisfirehose-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "build" }, { "name": "@aws-cdk/aws-kinesisfirehose-destinations-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "build" }, { "name": "@aws-cdk/integ-tests-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "build" }, { @@ -42,7 +42,7 @@ }, { "name": "aws-cdk-lib", - "version": "2.80.0", + "version": "2.85.0", "type": "build" }, { @@ -144,22 +144,22 @@ }, { "name": "@aws-cdk/aws-glue-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "devenv" }, { "name": "@aws-cdk/aws-kinesisfirehose-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "devenv" }, { "name": "@aws-cdk/aws-kinesisfirehose-destinations-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "devenv" }, { "name": "@aws-cdk/integ-tests-alpha", - "version": "2.80.0-alpha.0", + "version": "2.85.0-alpha.0", "type": "devenv" }, { @@ -174,27 +174,27 @@ }, { "name": "@aws-cdk/aws-glue-alpha", - "version": "^2.80.0-alpha.0", + "version": "^2.85.0-alpha.0", "type": "peer" }, { "name": "@aws-cdk/aws-kinesisfirehose-alpha", - "version": "^2.80.0-alpha.0", + "version": "^2.85.0-alpha.0", "type": "peer" }, { "name": "@aws-cdk/aws-kinesisfirehose-destinations-alpha", - "version": "^2.80.0-alpha.0", + "version": "^2.85.0-alpha.0", "type": "peer" }, { "name": "@aws-cdk/integ-tests-alpha", - "version": "^2.80.0-alpha.0", + "version": "^2.85.0-alpha.0", "type": "peer" }, { "name": "aws-cdk-lib", - "version": "^2.80.0", + "version": "^2.85.0", "type": "peer" }, { diff --git a/.projenrc.js b/.projenrc.js index 9345b7e5..b0cd32e9 100644 --- a/.projenrc.js +++ b/.projenrc.js @@ -1,6 +1,6 @@ const { awscdk, javascript, release, DependencyType } = require("projen"); -const CDK_VERSION = "2.80.0"; +const CDK_VERSION = "2.85.0"; const project = new awscdk.AwsCdkConstructLibrary({ author: "AWS Professional Services", diff --git a/API.md b/API.md index fcf42337..96f8f178 100644 --- a/API.md +++ b/API.md @@ -6589,6 +6589,8 @@ const appFlowIngestionStageProps: AppFlowIngestionStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -6650,6 +6652,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -6783,6 +6811,8 @@ const athenaToSQLStageProps: AthenaToSQLStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -6848,6 +6878,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -7029,6 +7085,7 @@ const baseStackProps: BaseStackProps = { ... } | env | aws-cdk-lib.Environment | The AWS environment (account/region) where this stack will be deployed. | | permissionsBoundary | aws-cdk-lib.PermissionsBoundary | Options for applying a permissions boundary to all IAM Roles and Users created within this Stage. | | stackName | string | Name to deploy the stack with. | +| suppressTemplateIndentation | boolean | Enable this flag to suppress indentation in generated CloudFormation templates. | | synthesizer | aws-cdk-lib.IStackSynthesizer | Synthesis method to use while deploying this stack. | | tags | {[ key: string ]: string} | Stack tags that will be applied to all the taggable resources and the stack itself. | | terminationProtection | boolean | Whether to enable termination protection for this stack. | @@ -7182,6 +7239,23 @@ Name to deploy the stack with. --- +##### `suppressTemplateIndentation`Optional + +```typescript +public readonly suppressTemplateIndentation: boolean; +``` + +- *Type:* boolean +- *Default:* the value of `@aws-cdk/core:suppressTemplateIndentation`, or `false` if that is not set. + +Enable this flag to suppress indentation in generated CloudFormation templates. + +If not specified, the value of the `@aws-cdk/core:suppressTemplateIndentation` +context key will be used. If that is not specified, then the +default value `false` will be used. + +--- + ##### `synthesizer`Optional ```typescript @@ -7290,6 +7364,7 @@ const cICDPipelineStackProps: CICDPipelineStackProps = { ... } | env | aws-cdk-lib.Environment | The AWS environment (account/region) where this stack will be deployed. | | permissionsBoundary | aws-cdk-lib.PermissionsBoundary | Options for applying a permissions boundary to all IAM Roles and Users created within this Stage. | | stackName | string | Name to deploy the stack with. | +| suppressTemplateIndentation | boolean | Enable this flag to suppress indentation in generated CloudFormation templates. | | synthesizer | aws-cdk-lib.IStackSynthesizer | Synthesis method to use while deploying this stack. | | tags | {[ key: string ]: string} | Stack tags that will be applied to all the taggable resources and the stack itself. | | terminationProtection | boolean | Whether to enable termination protection for this stack. | @@ -7445,6 +7520,23 @@ Name to deploy the stack with. --- +##### `suppressTemplateIndentation`Optional + +```typescript +public readonly suppressTemplateIndentation: boolean; +``` + +- *Type:* boolean +- *Default:* the value of `@aws-cdk/core:suppressTemplateIndentation`, or `false` if that is not set. + +Enable this flag to suppress indentation in generated CloudFormation templates. + +If not specified, the value of the `@aws-cdk/core:suppressTemplateIndentation` +context key will be used. If that is not specified, then the +default value `false` will be used. + +--- + ##### `synthesizer`Optional ```typescript @@ -7875,6 +7967,8 @@ const dataBrewTransformStageProps: DataBrewTransformStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -7952,6 +8046,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -9152,6 +9272,8 @@ const glueTransformStageProps: GlueTransformStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -9220,6 +9342,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -10037,6 +10185,8 @@ const mWAATriggerDagsStageProps: MWAATriggerDagsStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -10097,6 +10247,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -10266,6 +10442,8 @@ const redshiftDataApiStageProps: RedshiftDataApiStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -10327,6 +10505,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript @@ -10909,6 +11113,7 @@ const sqsToLambdaStageFunctionProps: SqsToLambdaStageFunctionProps = { ... } | logRetentionRetryOptions | aws-cdk-lib.aws_lambda.LogRetentionRetryOptions | When log retention is specified, a custom resource attempts to create the CloudWatch log group. | | logRetentionRole | aws-cdk-lib.aws_iam.IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. | | memorySize | number | The amount of memory, in MB, that is allocated to your Lambda function. | +| paramsAndSecrets | aws-cdk-lib.aws_lambda.ParamsAndSecretsLayerVersion | Specify the configuration of Parameters and Secrets Extension. | | profiling | boolean | Enable profiling. | | profilingGroup | aws-cdk-lib.aws_codeguruprofiler.IProfilingGroup | Profiling Group. | | reservedConcurrentExecutions | number | The maximum of concurrent executions you want to reserve for the function. | @@ -11326,6 +11531,21 @@ Developer Guide. --- +##### `paramsAndSecrets`Optional + +```typescript +public readonly paramsAndSecrets: ParamsAndSecretsLayerVersion; +``` + +- *Type:* aws-cdk-lib.aws_lambda.ParamsAndSecretsLayerVersion +- *Default:* No Parameters and Secrets Extension + +Specify the configuration of Parameters and Secrets Extension. + +> [https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html](https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html) + +--- + ##### `profiling`Optional ```typescript @@ -11833,6 +12053,8 @@ const stateMachineStageProps: StateMachineStageProps = { ... } | name | string | Name of the stage. | | additionalRolePolicyStatements | aws-cdk-lib.aws_iam.PolicyStatement[] | Additional IAM policy statements to add to the state machine role. | | alarmsEnabled | boolean | Enable/Disable all alarms in the stage. | +| definition | string \| aws-cdk-lib.aws_stepfunctions.IChainable | Steps for the state machine. | +| definitionFile | string | File containing a JSON definition for the state machine. | | stateMachineFailedExecutionsAlarmEvaluationPeriods | number | The number of periods over which data is compared to the specified threshold. | | stateMachineFailedExecutionsAlarmThreshold | number | The number of failed state machine executions before triggering CW alarm. | | stateMachineInput | {[ key: string ]: any} | Input of the state machine. | @@ -11889,6 +12111,32 @@ Enable/Disable all alarms in the stage. --- +##### `definition`Optional + +```typescript +public readonly definition: string | IChainable; +``` + +- *Type:* string | aws-cdk-lib.aws_stepfunctions.IChainable + +Steps for the state machine. + +Can either be provided as 'sfn.IChainable' or a JSON string. + +--- + +##### `definitionFile`Optional + +```typescript +public readonly definitionFile: string; +``` + +- *Type:* string + +File containing a JSON definition for the state machine. + +--- + ##### `stateMachineFailedExecutionsAlarmEvaluationPeriods`Optional ```typescript diff --git a/package.json b/package.json index 23a12208..c8b643a8 100644 --- a/package.json +++ b/package.json @@ -37,15 +37,15 @@ "organization": false }, "devDependencies": { - "@aws-cdk/aws-glue-alpha": "2.80.0-alpha.0", - "@aws-cdk/aws-kinesisfirehose-alpha": "2.80.0-alpha.0", - "@aws-cdk/aws-kinesisfirehose-destinations-alpha": "2.80.0-alpha.0", - "@aws-cdk/integ-tests-alpha": "2.80.0-alpha.0", + "@aws-cdk/aws-glue-alpha": "2.85.0-alpha.0", + "@aws-cdk/aws-kinesisfirehose-alpha": "2.85.0-alpha.0", + "@aws-cdk/aws-kinesisfirehose-destinations-alpha": "2.85.0-alpha.0", + "@aws-cdk/integ-tests-alpha": "2.85.0-alpha.0", "@types/jest": "^27", "@types/node": "^16", "@typescript-eslint/eslint-plugin": "^5", "@typescript-eslint/parser": "^5", - "aws-cdk-lib": "2.80.0", + "aws-cdk-lib": "2.85.0", "constructs": "10.0.5", "eslint": "^8", "eslint-config-prettier": "^8.8.0", @@ -67,11 +67,11 @@ "typescript": "^4.9.5" }, "peerDependencies": { - "@aws-cdk/aws-glue-alpha": "^2.80.0-alpha.0", - "@aws-cdk/aws-kinesisfirehose-alpha": "^2.80.0-alpha.0", - "@aws-cdk/aws-kinesisfirehose-destinations-alpha": "^2.80.0-alpha.0", - "@aws-cdk/integ-tests-alpha": "^2.80.0-alpha.0", - "aws-cdk-lib": "^2.80.0", + "@aws-cdk/aws-glue-alpha": "^2.85.0-alpha.0", + "@aws-cdk/aws-kinesisfirehose-alpha": "^2.85.0-alpha.0", + "@aws-cdk/aws-kinesisfirehose-destinations-alpha": "^2.85.0-alpha.0", + "@aws-cdk/integ-tests-alpha": "^2.85.0-alpha.0", + "aws-cdk-lib": "^2.85.0", "constructs": "^10.0.5" }, "dependencies": { diff --git a/src/pipelines/stage.ts b/src/pipelines/stage.ts index c7a9500f..f98387f1 100644 --- a/src/pipelines/stage.ts +++ b/src/pipelines/stage.ts @@ -163,10 +163,40 @@ export abstract class DataStage extends Stage { } } +function getDefinitionBody(definition?: sfn.IChainable | string, definitionFile?: string): sfn.DefinitionBody { + if (definition && definitionFile) { + throw new Error("Only one of 'definition' or 'definitionFile' should be provided."); + } + if (!definition && !definitionFile) { + throw new Error("One of 'definition' or 'definitionFile' must be provided."); + } + + if (definitionFile) { + return sfn.DefinitionBody.fromFile(definitionFile, {}); + } else { + if (typeof definition == "string") { + return sfn.DefinitionBody.fromString(definition); + } + if (definition) { + return sfn.DefinitionBody.fromChainable(definition); + } + } + throw new Error("Not able to create a definition body."); +} + /** * Properties of a state machine stage. */ export interface StateMachineStageProps extends StageProps { + /** + * Steps for the state machine. + * Can either be provided as 'sfn.IChainable' or a JSON string. + */ + readonly definition?: sfn.IChainable | string; + /** + * File containing a JSON definition for the state machine. + */ + readonly definitionFile?: string; /** * Input of the state machine. */ @@ -223,13 +253,12 @@ export abstract class StateMachineStage extends DataStage { /** * Constructs a state machine from the definition. - * @param definition Steps for the state machine. * @param props State machine stage properties. * @returns Dictionary with event pattern, targets and state machine construct. */ - protected createStateMachine(definition: sfn.IChainable, props: StateMachineStageProps): CreateStateMachineResult { + protected createStateMachine(props: StateMachineStageProps): CreateStateMachineResult { const stateMachine = new sfn.StateMachine(this, "State Machine", { - definition: definition, + definitionBody: getDefinitionBody(props.definition, props.definitionFile), stateMachineName: props.stateMachineName, }); diff --git a/src/stages/appflow-ingestion.ts b/src/stages/appflow-ingestion.ts index 0cc9f465..28892723 100644 --- a/src/stages/appflow-ingestion.ts +++ b/src/stages/appflow-ingestion.ts @@ -105,7 +105,7 @@ export class AppFlowIngestionStage extends StateMachineStage { eventPattern: this.eventPattern, targets: this.targets, stateMachine: this.stateMachine, - } = this.createStateMachine(definition, props)); + } = this.createStateMachine({ definition: definition, ...props })); this.stateMachine.addToRolePolicy( new iam.PolicyStatement({ effect: iam.Effect.ALLOW, diff --git a/src/stages/athena-sql.ts b/src/stages/athena-sql.ts index 93006cb8..e776167d 100644 --- a/src/stages/athena-sql.ts +++ b/src/stages/athena-sql.ts @@ -102,7 +102,10 @@ export class AthenaSQLStage extends StateMachineStage { const definition = athenaQueryExec.next(new sfn.Succeed(this, "Success")); - ({ eventPattern: this.eventPattern, stateMachine: this.stateMachine } = this.createStateMachine(definition, props)); + ({ eventPattern: this.eventPattern, stateMachine: this.stateMachine } = this.createStateMachine({ + definition: definition, + ...props, + })); this.targets = [ new eventsTargets.SfnStateMachine(this.stateMachine, { input: props.queryString diff --git a/src/stages/databrew-transform.ts b/src/stages/databrew-transform.ts index 1e78bdf1..06d4ddb3 100644 --- a/src/stages/databrew-transform.ts +++ b/src/stages/databrew-transform.ts @@ -192,7 +192,7 @@ export class DataBrewTransformStage extends StateMachineStage { eventPattern: this.eventPattern, targets: this.targets, stateMachine: this.stateMachine, - } = this.createStateMachine(definition, props)); + } = this.createStateMachine({ definition: definition, ...props })); } private createDefaultDataBrewJobRole(): iam.Role { diff --git a/src/stages/glue-transform.ts b/src/stages/glue-transform.ts index 5bdd5965..5347b019 100644 --- a/src/stages/glue-transform.ts +++ b/src/stages/glue-transform.ts @@ -131,7 +131,7 @@ export class GlueTransformStage extends StateMachineStage { eventPattern: this.eventPattern, targets: this.targets, stateMachine: this.stateMachine, - } = this.createStateMachine(definition, props)); + } = this.createStateMachine({ definition: definition, ...props })); } private getGlueJob(scope: Construct, id: string, props: GlueTransformStageProps): glue_alpha.IJob { diff --git a/src/stages/mwaa-trigger-dags.ts b/src/stages/mwaa-trigger-dags.ts index d26cb152..57201551 100644 --- a/src/stages/mwaa-trigger-dags.ts +++ b/src/stages/mwaa-trigger-dags.ts @@ -95,7 +95,7 @@ export class MWAATriggerDagsStage extends StateMachineStage { eventPattern: this.eventPattern, targets: this.targets, stateMachine: this.stateMachine, - } = this.createStateMachine(definition, props)); + } = this.createStateMachine({ definition: definition, ...props })); } private buildLambdas(): MWAALambdasResult { diff --git a/src/stages/redshift-data-api.ts b/src/stages/redshift-data-api.ts index 4eab8e2d..3b97303d 100644 --- a/src/stages/redshift-data-api.ts +++ b/src/stages/redshift-data-api.ts @@ -102,7 +102,10 @@ export class RedshiftDataApiStage extends StateMachineStage { .otherwise(wait), ); - ({ eventPattern: this.eventPattern, stateMachine: this.stateMachine } = this.createStateMachine(definition, props)); + ({ eventPattern: this.eventPattern, stateMachine: this.stateMachine } = this.createStateMachine({ + definition: definition, + ...props, + })); this.stateMachine.addToRolePolicy( new iam.PolicyStatement({ effect: iam.Effect.ALLOW, diff --git a/test/base-stack.test.ts b/test/base-stack.test.ts index 0ac57dd0..37a422bd 100644 --- a/test/base-stack.test.ts +++ b/test/base-stack.test.ts @@ -333,7 +333,7 @@ test("Test Permissions Boundary Creation and Usage in BaseStack", () => { const stackTemplate = Template.fromStack(stack); stackTemplate.hasResourceProperties("AWS::IAM::Role", { PermissionsBoundary: { - Ref: "DDKDefaultPermissionsBoundary6721F63A", + "Fn::ImportValue": "my-bootstrap-stack:ExportsOutputRefDDKDefaultPermissionsBoundary6721F63A9C9C311E", }, }); }); diff --git a/test/sfn-stage.test.ts b/test/sfn-stage.test.ts new file mode 100644 index 00000000..abe27d20 --- /dev/null +++ b/test/sfn-stage.test.ts @@ -0,0 +1,56 @@ +import * as cdk from "aws-cdk-lib"; +import * as events from "aws-cdk-lib/aws-events"; +import * as sfn from "aws-cdk-lib/aws-stepfunctions"; +import { Construct } from "constructs"; + +import { StateMachineStage, StateMachineStageProps } from "../src"; + +class TestSFNStage extends StateMachineStage { + readonly targets?: events.IRuleTarget[]; + readonly eventPattern?: events.EventPattern; + readonly stateMachine: sfn.StateMachine; + + constructor(scope: Construct, id: string, props: StateMachineStageProps) { + super(scope, id, props); + ({ + eventPattern: this.eventPattern, + targets: this.targets, + stateMachine: this.stateMachine, + } = this.createStateMachine({ + definition: props.definition, + definitionFile: props.definitionFile, + ...props, + })); + } +} + +test("State Machine Stage Definition File", () => { + const stack = new cdk.Stack(); + new TestSFNStage(stack, "MySFN", { + definitionFile: "./test/test-sfn-config.json", + }); +}); + +test("State Machine Stage Definition String", () => { + const stack = new cdk.Stack(); + new TestSFNStage(stack, "MySFN", { + definition: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', + }); +}); + +test("SFN No Definition", () => { + const stack = new cdk.Stack(); + expect(() => { + new TestSFNStage(stack, "MySFN", {}); + }).toThrowError("One of 'definition' or 'definitionFile' must be provided."); +}); + +test("SFN Redundant Definitions", () => { + const stack = new cdk.Stack(); + expect(() => { + new TestSFNStage(stack, "MySFN", { + definition: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', + definitionFile: "./test/test-sfn-config.json", + }); + }).toThrowError("Only one of 'definition' or 'definitionFile' should be provided."); +}); diff --git a/test/test-sfn-config.json b/test/test-sfn-config.json new file mode 100644 index 00000000..90e8fe09 --- /dev/null +++ b/test/test-sfn-config.json @@ -0,0 +1,94 @@ +{ + "StartAt": "random-number-generator-lambda-config", + "States": { + + + "random-number-generator-lambda-config": { + "Comment": "To configure the random-number-generator-lambda.", + "Type": "Pass", + "Result": { + "min": 1, + "max": 10 + }, + "ResultPath": "$", + "Next": "random-number-generator-lambda" + }, + + + "random-number-generator-lambda": { + "Comment": "Generate a number based on input.", + "Type": "Task", + "Resource": "${random-number-generator-lambda-aws-arn}", + "Next": "send-notification-if-less-than-5" + }, + + + "send-notification-if-less-than-5": { + "Comment": "A choice state to decide to send out notification for <5 or trigger power of three lambda for >5.", + "Type": "Choice", + "Choices": [ + { + "Variable": "$", + "NumericGreaterThanEquals": 5, + "Next": "power-of-three-lambda" + }, + { + "Variable": "$", + "NumericLessThan": 5, + "Next": "send-multiple-notification" + } + ] + }, + + + "power-of-three-lambda": { + "Comment": "Increase the input to power of 3 with customized input.", + "Type": "Task", + "Parameters" : { + "base.$": "$", + "exponent": 3 + }, + "Resource": "${power-of-number-lambda-aws-arn}", + "End": true + }, + + + "send-multiple-notification": { + "Comment": "Trigger multiple notification using AWS SNS", + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "send-sms-notification", + "States": { + "send-sms-notification": { + "Type": "Task", + "Resource": "arn:aws:states:::sns:publish", + "Parameters": { + "Message": "SMS: Random number is less than 5 $", + "PhoneNumber": "${valid-handphone-number}" + }, + "End": true + } + } + }, + { + "StartAt": "send-sns-topic", + "States": { + "send-sns-topic": { + "Type": "Task", + "Resource": "arn:aws:states:::sns:publish", + "Parameters": { + "Message": "Email: Random number is less than 5: $", + "TopicArn": "${aws-sns-topic-to-send-out-email}" + }, + "End": true + } + } + } + ] + } + + + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ce8cb546..bc38095f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,25 +30,25 @@ resolved "https://registry.yarnpkg.com/@aws-cdk/asset-node-proxy-agent-v5/-/asset-node-proxy-agent-v5-2.0.165.tgz#c169599d83beceea7e638082ef9833997f04c85d" integrity sha512-bsyLQD/vqXQcc9RDmlM1XqiFNO/yewgVFXmkMcQkndJbmE/jgYkzewwYGrBlfL725hGLQipXq19+jwWwdsXQqg== -"@aws-cdk/aws-glue-alpha@2.80.0-alpha.0": - version "2.80.0-alpha.0" - resolved "https://registry.yarnpkg.com/@aws-cdk/aws-glue-alpha/-/aws-glue-alpha-2.80.0-alpha.0.tgz#56d221c2ed6d110c2e51178c8911efbb87a14745" - integrity sha512-EL6ok3PVsm2rHn5HVqG6ekvty3NekwU2thqwmrylfg2qzeVOYww9iqXCrj85MNviWIccOlAAoeT62tOVZLFE+w== - -"@aws-cdk/aws-kinesisfirehose-alpha@2.80.0-alpha.0": - version "2.80.0-alpha.0" - resolved "https://registry.yarnpkg.com/@aws-cdk/aws-kinesisfirehose-alpha/-/aws-kinesisfirehose-alpha-2.80.0-alpha.0.tgz#287cff047227ceed7e23f568c67439ddec76b937" - integrity sha512-nw885HQZPzKpR/ofUeY7ofZjPwsCkDsWCFPWa8dSHymUCKhUrBnUFClLS81IHfc7QGUPVz/O40S6nFfoFAFbLQ== - -"@aws-cdk/aws-kinesisfirehose-destinations-alpha@2.80.0-alpha.0": - version "2.80.0-alpha.0" - resolved "https://registry.yarnpkg.com/@aws-cdk/aws-kinesisfirehose-destinations-alpha/-/aws-kinesisfirehose-destinations-alpha-2.80.0-alpha.0.tgz#c4bed0156fcb19080c14ea7e733e1a890b45a089" - integrity sha512-A+B4BQrymvpM896BVqqo3ATM2SzQUj/IqxIMxW4zQjZegjizsEh1kMAprERWdAHKqKByeDi69fR/EgQ9HPhdCQ== - -"@aws-cdk/integ-tests-alpha@2.80.0-alpha.0": - version "2.80.0-alpha.0" - resolved "https://registry.yarnpkg.com/@aws-cdk/integ-tests-alpha/-/integ-tests-alpha-2.80.0-alpha.0.tgz#d232c3885347336b9da0289c180675482c5d2a9f" - integrity sha512-XU5+8pqd2sUvxfyz6zluskydX1pY+NGL5jtZf2sUukkqN1PNQ/zZrQwyY6An8mCGggSwj0uMGrzItiuDKaiGuA== +"@aws-cdk/aws-glue-alpha@2.85.0-alpha.0": + version "2.85.0-alpha.0" + resolved "https://registry.yarnpkg.com/@aws-cdk/aws-glue-alpha/-/aws-glue-alpha-2.85.0-alpha.0.tgz#98c9fe33452fa2ceadb17140c3b35da0101c944a" + integrity sha512-xCvDdpTjJPM7dI6n1wZaBnPpmG3bhHcFYqkoh6WJQ+7HY2WAIL08UqBT3iRaz3WSu0ZT6qyhQxzD+r63p+BKMw== + +"@aws-cdk/aws-kinesisfirehose-alpha@2.85.0-alpha.0": + version "2.85.0-alpha.0" + resolved "https://registry.yarnpkg.com/@aws-cdk/aws-kinesisfirehose-alpha/-/aws-kinesisfirehose-alpha-2.85.0-alpha.0.tgz#a9ccaeeace3748101bb53f208ecac2ff0d9b9566" + integrity sha512-DjNNw7lIoq6yGi4ME7EGumlkwvV+HPvKMyFkNu2nJYud025pnGofLSEzAVrkvCwzoauFoue6db+r+mj0fP+KXw== + +"@aws-cdk/aws-kinesisfirehose-destinations-alpha@2.85.0-alpha.0": + version "2.85.0-alpha.0" + resolved "https://registry.yarnpkg.com/@aws-cdk/aws-kinesisfirehose-destinations-alpha/-/aws-kinesisfirehose-destinations-alpha-2.85.0-alpha.0.tgz#5bab42d60718b5761159af4e9931d951ccce0a11" + integrity sha512-5nKBD5voMIxoJl/nTZ3WGeLG8glWHfCQgroOLI7pCYAz/M+mjcxlyuE8jUuvQZy+a1XMLVjpN2SdsfXZypDaTQ== + +"@aws-cdk/integ-tests-alpha@2.85.0-alpha.0": + version "2.85.0-alpha.0" + resolved "https://registry.yarnpkg.com/@aws-cdk/integ-tests-alpha/-/integ-tests-alpha-2.85.0-alpha.0.tgz#cf72248d3a0c2581eae13a8f190a33dbd5a913fc" + integrity sha512-tqURxQZnFYc0Quj58LOE7A2QoBxppPLwJgZalLBkhJgAsfARi42TU8uh14Ov/4Kk5KUEeL6pguyFy2xYvJSLCA== "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.5": version "7.22.5" @@ -1386,10 +1386,10 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -aws-cdk-lib@2.80.0: - version "2.80.0" - resolved "https://registry.yarnpkg.com/aws-cdk-lib/-/aws-cdk-lib-2.80.0.tgz#1118860637d33fab8f646551c29a75728404b64e" - integrity sha512-PoqD3Yms5I0ajuTi071nTW/hpkH3XsdyZzn5gYsPv0qD7mqP3h6Qr+6RiGx+yQ1KcVFyxWdX15uK+DsC0KwvcQ== +aws-cdk-lib@2.85.0: + version "2.85.0" + resolved "https://registry.yarnpkg.com/aws-cdk-lib/-/aws-cdk-lib-2.85.0.tgz#09a577799b63107d3128c2755ee02acedc580e5d" + integrity sha512-u+ypK8XEMRH3tGRMSmcbPYxLet7xBdGIztUkMcPtlNJGhS/vxqh12yYkem3g3zzmHwdX8OPLSnlZ2sIuiIqp/g== dependencies: "@aws-cdk/asset-awscli-v1" "^2.2.177" "@aws-cdk/asset-kubectl-v20" "^2.1.1"