diff --git a/CHANGELOG.md b/CHANGELOG.md index b845e6965..633ed1db3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.74.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.73.0...v2.74.0) (2024-10-22) + +Build on CDK v2.161.0 + +### Features + +* **aws-sqs-pipes-stepfunctions:** accept existing state machine ([#1223](https://github.com/awslabs/aws-solutions-constructs/issues/1223)) + ## [2.73.0](https://github.com/awslabs/aws-solutions-constructs/compare/v2.72.0...v2.73.0) (2024-10-21) Build on CDK v2.161.0 diff --git a/source/lerna.json b/source/lerna.json index 796014f02..770425e98 100644 --- a/source/lerna.json +++ b/source/lerna.json @@ -5,5 +5,5 @@ "patterns/@aws-solutions-constructs/*" ], "rejectCycles": "true", - "version": "2.73.0" + "version": "2.74.0" } diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/lib/index.ts index 6a6391d2f..55788e130 100644 --- a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/lib/index.ts @@ -82,9 +82,13 @@ export interface SqsToPipesToStepfunctionsProps { // ******************* /** - * User provided props for the sfn.StateMachine. + * User provided props for the sfn.StateMachine. This or existingStateMachine is required */ - readonly stateMachineProps: sfn.StateMachineProps, + readonly stateMachineProps?: sfn.StateMachineProps, + /** + * Optional existing state machine to incorporate into the construct + */ + readonly existingStateMachineObj?: sfn.StateMachine, /** * Whether to create recommended CloudWatch alarms * @@ -143,7 +147,7 @@ export interface SqsToPipesToStepfunctionsProps { export class SqsToPipesToStepfunctions extends Construct { public readonly stateMachine: sfn.StateMachine; - public readonly stateMachineLogGroup: logs.ILogGroup; + public readonly stateMachineLogGroup?: logs.ILogGroup; public readonly cloudwatchAlarms?: cloudwatch.Alarm[]; public readonly sqsQueue: sqs.Queue; public readonly deadLetterQueue?: sqs.DeadLetterQueue; @@ -180,14 +184,18 @@ export class SqsToPipesToStepfunctions extends Construct { this.deadLetterQueue = buildQueueResponse.dlq; // Create the State Machine - const buildStateMachineResponse = defaults.buildStateMachine(this, defaults.idPlaceholder, { - stateMachineProps: props.stateMachineProps, - logGroupProps: props.logGroupProps, - createCloudWatchAlarms: props.createCloudWatchAlarms, - }); - this.stateMachine = buildStateMachineResponse.stateMachine; - this.stateMachineLogGroup = buildStateMachineResponse.logGroup; - this.cloudwatchAlarms = buildStateMachineResponse.cloudWatchAlarms; + if (!props.existingStateMachineObj) { + const buildStateMachineResponse = defaults.buildStateMachine(this, defaults.idPlaceholder, { + stateMachineProps: props.stateMachineProps!, // CheckStateMachineProps ensures this is defined if existingStateMachineObj is not + logGroupProps: props.logGroupProps, + createCloudWatchAlarms: props.createCloudWatchAlarms, + }); + this.stateMachine = buildStateMachineResponse.stateMachine; + this.stateMachineLogGroup = buildStateMachineResponse.logGroup; + this.cloudwatchAlarms = buildStateMachineResponse.cloudWatchAlarms; + } else { + this.stateMachine = props.existingStateMachineObj; + } // Create the pipe to connect the queue and state machine const buildPipeResponse = defaults.BuildPipe(this, id, { diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/cdk.out b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/cdk.out new file mode 100644 index 000000000..c6e612584 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"38.0.1"} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/integ.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/integ.json new file mode 100644 index 000000000..ce82e7673 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "38.0.1", + "testCases": { + "sqspstp-existing-state-machine/Integ/DefaultTest": { + "stacks": [ + "sqspstp-existing-state-machine" + ], + "assertionStack": "sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert", + "assertionStackName": "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3" + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/manifest.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/manifest.json new file mode 100644 index 000000000..81383faff --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/manifest.json @@ -0,0 +1,181 @@ +{ + "version": "38.0.1", + "artifacts": { + "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "notificationArns": [], + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets" + ], + "metadata": { + "/sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert" + }, + "sqspstp-existing-state-machine.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "sqspstp-existing-state-machine.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "sqspstp-existing-state-machine": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "sqspstp-existing-state-machine.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "notificationArns": [], + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/efb8bb9236fcf45e0d14ab1780f81cd6356f45fa6efd47a3ac79e7f913fa8fb6.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "sqspstp-existing-state-machine.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "sqspstp-existing-state-machine.assets" + ], + "metadata": { + "/sqspstp-existing-state-machine/lambdas3stp-test-state-machine/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "lambdas3stpteststatemachineServiceRole06C303CC" + } + ], + "/sqspstp-existing-state-machine/lambdas3stp-test-state-machine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "lambdas3stpteststatemachine14912CBC" + } + ], + "/sqspstp-existing-state-machine/s3stp-test-state-machine/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "s3stpteststatemachineRoleF95DAD26" + } + ], + "/sqspstp-existing-state-machine/s3stp-test-state-machine/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "s3stpteststatemachineRoleDefaultPolicy9B0BD12F" + } + ], + "/sqspstp-existing-state-machine/s3stp-test-state-machine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "s3stpteststatemachine6717B458" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructqueuedlq420A82FD" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq/Policy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructqueuedlqPolicyB1D70483" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructqueueA7C76715" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue/Policy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructqueuePolicyFD32B562" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/PipeRole--test-sqs-pipes-states-construct/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructPipeRoletestsqspipesstatesconstruct2CC9A13C" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/LogGroup-test-sqs-pipes-states-construct/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructLogGrouptestsqspipesstatesconstructF827FE15" + } + ], + "/sqspstp-existing-state-machine/test-sqs-pipes-states-construct/pipe-test-sqs-pipes-states-construct": [ + { + "type": "aws:cdk:logicalId", + "data": "testsqspipesstatesconstructpipetestsqspipesstatesconstruct71A64A15" + } + ], + "/sqspstp-existing-state-machine/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/sqspstp-existing-state-machine/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "sqspstp-existing-state-machine" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.assets.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.assets.json new file mode 100644 index 000000000..9b2d7d2f8 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.assets.json @@ -0,0 +1,19 @@ +{ + "version": "38.0.1", + "files": { + "efb8bb9236fcf45e0d14ab1780f81cd6356f45fa6efd47a3ac79e7f913fa8fb6": { + "source": { + "path": "sqspstp-existing-state-machine.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "efb8bb9236fcf45e0d14ab1780f81cd6356f45fa6efd47a3ac79e7f913fa8fb6.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.template.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.template.json new file mode 100644 index 000000000..118ffef1f --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstp-existing-state-machine.template.json @@ -0,0 +1,510 @@ +{ + "Resources": { + "lambdas3stpteststatemachineServiceRole06C303CC": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "lambdas3stpteststatemachine14912CBC": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => console.log(event)" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "lambdas3stpteststatemachineServiceRole06C303CC", + "Arn" + ] + }, + "Runtime": "nodejs20.x" + }, + "DependsOn": [ + "lambdas3stpteststatemachineServiceRole06C303CC" + ], + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W58", + "reason": "This Lambda Function is created for integration testing purposes only and is not part of an actual construct" + }, + { + "id": "W89", + "reason": "This Lambda Function is created for integration testing purposes only and is not part of an actual construct" + }, + { + "id": "W92", + "reason": "This Lambda Function is created for integration testing purposes only and is not part of an actual construct" + } + ] + } + } + }, + "s3stpteststatemachineRoleF95DAD26": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "s3stpteststatemachineRoleDefaultPolicy9B0BD12F": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + ":*" + ] + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "s3stpteststatemachineRoleDefaultPolicy9B0BD12F", + "Roles": [ + { + "Ref": "s3stpteststatemachineRoleF95DAD26" + } + ] + } + }, + "s3stpteststatemachine6717B458": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"tasks3stp-test-state-machine\",\"States\":{\"tasks3stp-test-state-machine\":{\"End\":true,\"Retry\":[{\"ErrorEquals\":[\"Lambda.ClientExecutionTimeoutException\",\"Lambda.ServiceException\",\"Lambda.AWSLambdaException\",\"Lambda.SdkClientException\"],\"IntervalSeconds\":2,\"MaxAttempts\":6,\"BackoffRate\":2}],\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::lambda:invoke\",\"Parameters\":{\"FunctionName\":\"", + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + "\",\"Payload.$\":\"$\"}}}}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "s3stpteststatemachineRoleF95DAD26", + "Arn" + ] + } + }, + "DependsOn": [ + "s3stpteststatemachineRoleDefaultPolicy9B0BD12F", + "s3stpteststatemachineRoleF95DAD26" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "testsqspipesstatesconstructqueuedlq420A82FD": { + "Type": "AWS::SQS::Queue", + "Properties": { + "KmsMasterKeyId": "alias/aws/sqs" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "testsqspipesstatesconstructqueuedlqPolicyB1D70483": { + "Type": "AWS::SQS::QueuePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "sqs:AddPermission", + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage", + "sqs:RemovePermission", + "sqs:SendMessage", + "sqs:SetQueueAttributes" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "Sid": "QueueOwnerOnlyAccess" + }, + { + "Action": "SQS:*", + "Condition": { + "Bool": { + "aws:SecureTransport": "false" + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "Sid": "HttpsOnly" + } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "testsqspipesstatesconstructqueuedlq420A82FD" + } + ] + } + }, + "testsqspipesstatesconstructqueueA7C76715": { + "Type": "AWS::SQS::Queue", + "Properties": { + "KmsMasterKeyId": "alias/aws/sqs", + "RedrivePolicy": { + "deadLetterTargetArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "maxReceiveCount": 15 + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "testsqspipesstatesconstructqueuePolicyFD32B562": { + "Type": "AWS::SQS::QueuePolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "sqs:AddPermission", + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage", + "sqs:RemovePermission", + "sqs:SendMessage", + "sqs:SetQueueAttributes" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "Sid": "QueueOwnerOnlyAccess" + }, + { + "Action": "SQS:*", + "Condition": { + "Bool": { + "aws:SecureTransport": "false" + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "Sid": "HttpsOnly" + } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "testsqspipesstatesconstructqueueA7C76715" + } + ] + } + }, + "testsqspipesstatesconstructPipeRoletestsqspipesstatesconstruct2CC9A13C": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "pipes.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "sourcePolicy" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "s3stpteststatemachine6717B458" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "targetPolicy" + } + ] + }, + "Metadata": { + "guard": { + "SuppressedRules": [ + "IAM_NO_INLINE_POLICY_CHECK" + ] + } + } + }, + "testsqspipesstatesconstructLogGrouptestsqspipesstatesconstructF827FE15": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "LogGroupName": { + "Fn::Join": [ + "", + [ + "/aws/vendedlogs/pipes/constructs/sqspstp-existing-state-machinetest-sqs-pipes-states-constructPipesLog-", + { + "Fn::Select": [ + 2, + { + "Fn::Split": [ + "/", + { + "Ref": "AWS::StackId" + } + ] + } + ] + } + ] + ] + } + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W86", + "reason": "Retention period for CloudWatchLogs LogGroups are set to 'Never Expire' to preserve customer data indefinitely" + }, + { + "id": "W84", + "reason": "By default CloudWatchLogs LogGroups data is encrypted using the CloudWatch server-side encryption keys (AWS Managed Keys)" + } + ] + } + } + }, + "testsqspipesstatesconstructpipetestsqspipesstatesconstruct71A64A15": { + "Type": "AWS::Pipes::Pipe", + "Properties": { + "LogConfiguration": { + "CloudwatchLogsLogDestination": { + "LogGroupArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructLogGrouptestsqspipesstatesconstructF827FE15", + "Arn" + ] + } + }, + "Level": "INFO" + }, + "RoleArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructPipeRoletestsqspipesstatesconstruct2CC9A13C", + "Arn" + ] + }, + "Source": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "SourceParameters": {}, + "Target": { + "Ref": "s3stpteststatemachine6717B458" + }, + "TargetParameters": { + "StepFunctionStateMachineParameters": { + "InvocationType": "FIRE_AND_FORGET" + } + } + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets.json new file mode 100644 index 000000000..6dc9c80e4 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.assets.json @@ -0,0 +1,19 @@ +{ + "version": "38.0.1", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.template.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.template.json new file mode 100644 index 000000000..ad9d0fb73 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/sqspstpexistingstatemachineIntegDefaultTestDeployAssertE03331F3.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/tree.json b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/tree.json new file mode 100644 index 000000000..a4b50ea17 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.js.snapshot/tree.json @@ -0,0 +1,767 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "sqspstp-existing-state-machine": { + "id": "sqspstp-existing-state-machine", + "path": "sqspstp-existing-state-machine", + "children": { + "lambdas3stp-test-state-machine": { + "id": "lambdas3stp-test-state-machine", + "path": "sqspstp-existing-state-machine/lambdas3stp-test-state-machine", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "sqspstp-existing-state-machine/lambdas3stp-test-state-machine/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "sqspstp-existing-state-machine/lambdas3stp-test-state-machine/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "2.161.0" + } + }, + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/lambdas3stp-test-state-machine/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "2.161.0" + } + }, + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/lambdas3stp-test-state-machine/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = async (event) => console.log(event)" + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "lambdas3stpteststatemachineServiceRole06C303CC", + "Arn" + ] + }, + "runtime": "nodejs20.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Function", + "version": "2.161.0" + } + }, + "tasks3stp-test-state-machine": { + "id": "tasks3stp-test-state-machine", + "path": "sqspstp-existing-state-machine/tasks3stp-test-state-machine", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.LambdaInvoke", + "version": "2.161.0" + } + }, + "s3stp-test-state-machine": { + "id": "s3stp-test-state-machine", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine", + "children": { + "Role": { + "id": "Role", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Role/ImportRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "2.161.0" + } + }, + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "2.161.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + ":*" + ] + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "policyName": "s3stpteststatemachineRoleDefaultPolicy9B0BD12F", + "roles": [ + { + "Ref": "s3stpteststatemachineRoleF95DAD26" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "2.161.0" + } + }, + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/s3stp-test-state-machine/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::StepFunctions::StateMachine", + "aws:cdk:cloudformation:props": { + "definitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"tasks3stp-test-state-machine\",\"States\":{\"tasks3stp-test-state-machine\":{\"End\":true,\"Retry\":[{\"ErrorEquals\":[\"Lambda.ClientExecutionTimeoutException\",\"Lambda.ServiceException\",\"Lambda.AWSLambdaException\",\"Lambda.SdkClientException\"],\"IntervalSeconds\":2,\"MaxAttempts\":6,\"BackoffRate\":2}],\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::lambda:invoke\",\"Parameters\":{\"FunctionName\":\"", + { + "Fn::GetAtt": [ + "lambdas3stpteststatemachine14912CBC", + "Arn" + ] + }, + "\",\"Payload.$\":\"$\"}}}}" + ] + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "s3stpteststatemachineRoleF95DAD26", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine", + "version": "2.161.0" + } + }, + "test-sqs-pipes-states-construct": { + "id": "test-sqs-pipes-states-construct", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct", + "children": { + "queue-dlq": { + "id": "queue-dlq", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SQS::Queue", + "aws:cdk:cloudformation:props": { + "kmsMasterKeyId": "alias/aws/sqs" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.CfnQueue", + "version": "2.161.0" + } + }, + "Policy": { + "id": "Policy", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq/Policy", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue-dlq/Policy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SQS::QueuePolicy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "sqs:AddPermission", + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage", + "sqs:RemovePermission", + "sqs:SendMessage", + "sqs:SetQueueAttributes" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "Sid": "QueueOwnerOnlyAccess" + }, + { + "Action": "SQS:*", + "Condition": { + "Bool": { + "aws:SecureTransport": "false" + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "Sid": "HttpsOnly" + } + ], + "Version": "2012-10-17" + }, + "queues": [ + { + "Ref": "testsqspipesstatesconstructqueuedlq420A82FD" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.CfnQueuePolicy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.QueuePolicy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.Queue", + "version": "2.161.0" + } + }, + "queue": { + "id": "queue", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SQS::Queue", + "aws:cdk:cloudformation:props": { + "kmsMasterKeyId": "alias/aws/sqs", + "redrivePolicy": { + "deadLetterTargetArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueuedlq420A82FD", + "Arn" + ] + }, + "maxReceiveCount": 15 + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.CfnQueue", + "version": "2.161.0" + } + }, + "Policy": { + "id": "Policy", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue/Policy", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/queue/Policy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SQS::QueuePolicy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "sqs:AddPermission", + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage", + "sqs:RemovePermission", + "sqs:SendMessage", + "sqs:SetQueueAttributes" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "Sid": "QueueOwnerOnlyAccess" + }, + { + "Action": "SQS:*", + "Condition": { + "Bool": { + "aws:SecureTransport": "false" + } + }, + "Effect": "Deny", + "Principal": { + "AWS": "*" + }, + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "Sid": "HttpsOnly" + } + ], + "Version": "2012-10-17" + }, + "queues": [ + { + "Ref": "testsqspipesstatesconstructqueueA7C76715" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.CfnQueuePolicy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.QueuePolicy", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_sqs.Queue", + "version": "2.161.0" + } + }, + "PipeRole--test-sqs-pipes-states-construct": { + "id": "PipeRole--test-sqs-pipes-states-construct", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/PipeRole--test-sqs-pipes-states-construct", + "children": { + "ImportPipeRole--test-sqs-pipes-states-construct": { + "id": "ImportPipeRole--test-sqs-pipes-states-construct", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/PipeRole--test-sqs-pipes-states-construct/ImportPipeRole--test-sqs-pipes-states-construct", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "2.161.0" + } + }, + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/PipeRole--test-sqs-pipes-states-construct/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "pipes.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "policies": [ + { + "policyName": "sourcePolicy", + "policyDocument": { + "Statement": [ + { + "Action": [ + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + } + }, + { + "policyName": "targetPolicy", + "policyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "s3stpteststatemachine6717B458" + } + } + ], + "Version": "2012-10-17" + } + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "2.161.0" + } + }, + "LogGroup-test-sqs-pipes-states-construct": { + "id": "LogGroup-test-sqs-pipes-states-construct", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/LogGroup-test-sqs-pipes-states-construct", + "children": { + "Resource": { + "id": "Resource", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/LogGroup-test-sqs-pipes-states-construct/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", + "aws:cdk:cloudformation:props": { + "logGroupName": { + "Fn::Join": [ + "", + [ + "/aws/vendedlogs/pipes/constructs/sqspstp-existing-state-machinetest-sqs-pipes-states-constructPipesLog-", + { + "Fn::Select": [ + 2, + { + "Fn::Split": [ + "/", + { + "Ref": "AWS::StackId" + } + ] + } + ] + } + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.CfnLogGroup", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_logs.LogGroup", + "version": "2.161.0" + } + }, + "pipe-test-sqs-pipes-states-construct": { + "id": "pipe-test-sqs-pipes-states-construct", + "path": "sqspstp-existing-state-machine/test-sqs-pipes-states-construct/pipe-test-sqs-pipes-states-construct", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Pipes::Pipe", + "aws:cdk:cloudformation:props": { + "logConfiguration": { + "cloudwatchLogsLogDestination": { + "logGroupArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructLogGrouptestsqspipesstatesconstructF827FE15", + "Arn" + ] + } + }, + "level": "INFO" + }, + "roleArn": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructPipeRoletestsqspipesstatesconstruct2CC9A13C", + "Arn" + ] + }, + "source": { + "Fn::GetAtt": [ + "testsqspipesstatesconstructqueueA7C76715", + "Arn" + ] + }, + "sourceParameters": {}, + "target": { + "Ref": "s3stpteststatemachine6717B458" + }, + "targetParameters": { + "stepFunctionStateMachineParameters": { + "invocationType": "FIRE_AND_FORGET" + } + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_pipes.CfnPipe", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-solutions-constructs/aws-sqs-pipes-stepfunctions.SqsToPipesToStepfunctions", + "version": "2.73.0" + } + }, + "Integ": { + "id": "Integ", + "path": "sqspstp-existing-state-machine/Integ", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "sqspstp-existing-state-machine/Integ/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "sqspstp-existing-state-machine/Integ/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "2.161.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "sqspstp-existing-state-machine/Integ/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "2.161.0-alpha.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "2.161.0-alpha.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "sqspstp-existing-state-machine/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "2.161.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "sqspstp-existing-state-machine/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "2.161.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "2.161.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "2.161.0" + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.ts new file mode 100644 index 000000000..203edf13b --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/integ.sqspstp-existing-state-machine.ts @@ -0,0 +1,33 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +/// !cdk-integ * +import { App, Stack } from "aws-cdk-lib"; +import { SqsToPipesToStepfunctions, SqsToPipesToStepfunctionsProps } from "../lib"; +import { generateIntegStackName } from '@aws-solutions-constructs/core'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import * as defaults from '@aws-solutions-constructs/core'; + +const app = new App(); +const stack = new Stack(app, generateIntegStackName(__filename)); + +const existingStateMachineObj = defaults.CreateTestStateMachine(stack, 's3stp-test-state-machine'); +const props: SqsToPipesToStepfunctionsProps = { + existingStateMachineObj +}; + +new SqsToPipesToStepfunctions(stack, 'test-sqs-pipes-states-construct', props); + +new IntegTest(stack, 'Integ', { testCases: [ + stack +] }); diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/sqs-pipes-stepfunctions.test.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/sqs-pipes-stepfunctions.test.ts index 9cbde4ec2..3f5c0d03f 100644 --- a/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/sqs-pipes-stepfunctions.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-pipes-stepfunctions/test/sqs-pipes-stepfunctions.test.ts @@ -15,6 +15,7 @@ import { Stack } from "aws-cdk-lib"; import { SqsToPipesToStepfunctions, SqsToPipesToStepfunctionsProps } from "../lib"; import { Match, Template } from 'aws-cdk-lib/assertions'; import * as sqs from 'aws-cdk-lib/aws-sqs'; +import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; import * as defaults from '@aws-solutions-constructs/core'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { RetentionDays } from "aws-cdk-lib/aws-logs"; @@ -130,6 +131,118 @@ test('Test default behaviors', () => { }); +test('Test existing state machine', () => { + // Initial Setup + const stack = new Stack(); + const stateMachine = defaults.CreateTestStateMachine(stack, 'state-machine'); + const props: SqsToPipesToStepfunctionsProps = { + existingStateMachineObj: stateMachine + }; + const construct = new SqsToPipesToStepfunctions(stack, 'test-sqs-pipes-states', props); + const template = Template.fromStack(stack); + + expect(construct.pipe).toBeDefined(); + expect(construct.pipeRole).toBeDefined(); + + template.resourceCountIs("AWS::StepFunctions::StateMachine", 1); + + template.hasResourceProperties('AWS::IAM::Role', { + AssumeRolePolicyDocument: { + Statement: [ + { + Action: "sts:AssumeRole", + Effect: "Allow", + Principal: { + Service: "pipes.amazonaws.com" + } + } + ], + Version: "2012-10-17" + }, + Policies: [ + { + PolicyDocument: { + Statement: [ + { + Action: [ + "sqs:ReceiveMessage", + "sqs:DeleteMessage", + "sqs:GetQueueAttributes" + ], + Effect: "Allow", + Resource: { + "Fn::GetAtt": [ + Match.stringLikeRegexp(`testsqspipesstatesqueue.*`), + "Arn" + ] + } + } + ], + Version: "2012-10-17" + }, + PolicyName: "sourcePolicy" + }, + { + PolicyDocument: { + Statement: [ + { + Action: "states:StartExecution", + Effect: "Allow", + Resource: { + Ref: Match.stringLikeRegexp(`statemachine.*`) + } + } + ], + Version: "2012-10-17" + }, + PolicyName: "targetPolicy" + } + ] + }); + template.hasResourceProperties('AWS::Pipes::Pipe', { + Source: { + "Fn::GetAtt": [ + Match.stringLikeRegexp(`testsqspipesstatesqueue.*`), + "Arn" + ] + }, + Target: { + Ref: Match.stringLikeRegexp(`statemachine.*`), + }, + }); + + template.hasResourceProperties('AWS::Pipes::Pipe', { + LogConfiguration: { + CloudwatchLogsLogDestination: { + LogGroupArn: { + "Fn::GetAtt": [ + Match.stringLikeRegexp(`testsqspipesstatesLogGrouptestsqspipesstates.*`), + "Arn" + ] + } + }, + Level: "INFO" + } + }); + template.hasResourceProperties('AWS::Logs::LogGroup', { + LogGroupName: { + "Fn::Join": [ + "", + [ + Match.stringLikeRegexp('\/aws\/vendedlogs\/pipes\/constructs'), + { + "Fn::Select": [ + 2, + Match.anyValue() + ] + } + ] + ] + }, + }); + +}); + test('Test queue and state machine aspects of construct', () => { // Initial Setup const stack = new Stack(); @@ -423,3 +536,22 @@ test('Test setting source parameters like batchSize', () => { } }); }); + +test('Test sending state machine props and existing state machine is an error', () => { + // These are all tested in CheckStateMachineProps, so this is just checking that CheckStateMachineProps is called. + + // Stack + const stack = new Stack(); + const props: SqsToPipesToStepfunctionsProps = { + stateMachineProps: { + definitionBody: defaults.CreateTestStateMachineDefinitionBody(stack, 'pipes-test') + }, + existingStateMachineObj: { pretend: "I'm A State Machine :-)"} as unknown as sfn.StateMachine, + }; + + const app = () => { + new SqsToPipesToStepfunctions(stack, 'test-sqs-pipes-states', props); + }; + // Assertion + expect(app).toThrowError('ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'); +}); diff --git a/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts index 9d2854e4b..0f31fa54d 100644 --- a/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts @@ -167,7 +167,8 @@ export function buildStepFunctionCWAlarms(scope: Construct, id: string | undefin } export interface StateMachineProps { - readonly stateMachineProps: sfn.StateMachineProps; + readonly stateMachineProps?: sfn.StateMachineProps; + readonly existingStateMachineObj?: sfn.StateMachine; readonly createCloudWatchAlarms?: boolean; readonly cloudWatchAlarmsPrefix?: string readonly logGroupProps?: logs.LogGroupProps; @@ -182,6 +183,16 @@ export function CheckStateMachineProps(propsObject: StateMachineProps | any) { errorFound = true; } + if ((propsObject.existingStateMachineObj) && + (propsObject.stateMachineProps || + (propsObject.createCloudWatchAlarms !== undefined) || + propsObject.cloudWatchAlarmsPrefix || + propsObject.logGroupProps)) { + + errorMessages += 'ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'; + errorFound = true; + } + if (errorFound) { throw new Error(errorMessages); } diff --git a/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts index 937d0d367..2f8d6152b 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts @@ -15,6 +15,7 @@ import { Stack, Aws } from "aws-cdk-lib"; import * as defaults from '../'; import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; +import * as logs from 'aws-cdk-lib/aws-logs'; import * as sfnTasks from 'aws-cdk-lib/aws-stepfunctions-tasks'; import { buildLogGroup } from '../lib/cloudwatch-log-group-helper'; import * as iam from 'aws-cdk-lib/aws-iam'; @@ -447,3 +448,43 @@ test('Confirm cloudWatchAlarmsPrefix requires createCloudWatchAlarms', () => { // Assertion expect(app).toThrowError('Error - cloudWatchAlarmsPrefix is invalid when createCloudWatchAlarms is false\n'); }); + +test('Confirm existingStateMachine disables all other state machine props', () => { + + const app = () => { + defaults.CheckStateMachineProps({ + existingStateMachineObj: { pretend: "I'm A State Machine :-)"} as unknown as sfn.StateMachine, + cloudWatchAlarmsPrefix: 'prefix' + }); + }; + // Assertion + expect(app).toThrowError('ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'); + + const app2 = () => { + defaults.CheckStateMachineProps({ + existingStateMachineObj: { pretend: "I'm A State Machine :-)"} as unknown as sfn.StateMachine, + stateMachineProps: { pretend: "I'm State Machine Props :-)"} as unknown as sfn.StateMachineProps, + }); + }; + // Assertion + expect(app2).toThrowError('ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'); + + const app3 = () => { + defaults.CheckStateMachineProps({ + existingStateMachineObj: { pretend: "I'm A State Machine :-)"} as unknown as sfn.StateMachine, + createCloudWatchAlarms: false + }); + }; + // Assertion + expect(app3).toThrowError('ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'); + + const app4 = () => { + defaults.CheckStateMachineProps({ + existingStateMachineObj: { pretend: "I'm A State Machine :-)"} as unknown as sfn.StateMachine, + logGroupProps: { pretend: "I'm State Machine Props :-)"} as unknown as logs.LogGroupProps, + }); + }; + // Assertion + expect(app4).toThrowError('ERROR - If existingStateMachine is provided, no other state machine props are allowed\n'); + +});