diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.assets.json new file mode 100644 index 0000000000000..fc26527706df7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "5a4a7364d62c5bab6b3ec3ccfa6d371f59724308214a3fd5da99da666d1c943a": { + "source": { + "path": "StartBuildBatch.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "5a4a7364d62c5bab6b3ec3ccfa6d371f59724308214a3fd5da99da666d1c943a.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/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.template.json new file mode 100644 index 0000000000000..baa81c2db7b3a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatch.template.json @@ -0,0 +1,364 @@ +{ + "Resources": { + "ProjectRole4CCB274E": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "ProjectRoleDefaultPolicy7F29461B": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + }, + ":*" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + } + ] + ] + } + ] + }, + { + "Action": [ + "codebuild:BatchPutCodeCoverages", + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:CreateReportGroup", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codebuild:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "ProjectC78D97AD" + }, + "-*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "ProjectRoleDefaultPolicy7F29461B", + "Roles": [ + { + "Ref": "ProjectRole4CCB274E" + } + ] + } + }, + "ProjectC78D97AD": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Artifacts": { + "Type": "NO_ARTIFACTS" + }, + "BuildBatchConfig": { + "ServiceRole": { + "Fn::GetAtt": [ + "ProjectBatchServiceRoleF97A1CFB", + "Arn" + ] + } + }, + "Cache": { + "Type": "NO_CACHE" + }, + "EncryptionKey": "alias/aws/s3", + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "Image": "aws/codebuild/standard:5.0", + "ImagePullCredentialsType": "CODEBUILD", + "PrivilegedMode": false, + "Type": "LINUX_CONTAINER" + }, + "Name": "MyTestProject", + "ServiceRole": { + "Fn::GetAtt": [ + "ProjectRole4CCB274E", + "Arn" + ] + }, + "Source": { + "BuildSpec": "version: 0.2\nbatch:\n fast-fail: true\n build-list:\n - identifier: linux_small\n env:\n compute-type: BUILD_GENERAL1_SMALL\n image: aws/codebuild/standard:5.0\n type: LINUX_CONTAINER\n variables:\n key1: value1\n buildspec: |-\n version: 0.2\n phases:\n build:\n commands:\n - echo \"Hello, from small!\"\n - identifier: linux_medium\n env:\n compute-type: BUILD_GENERAL1_MEDIUM\n image: aws/codebuild/standard:4.0\n type: LINUX_CONTAINER\n variables:\n key2: value2\n buildspec: |-\n version: 0.2\n phases:\n build:\n commands:\n - echo \"Hello, from medium!\"\n", + "Type": "NO_SOURCE" + }, + "TimeoutInMinutes": 60 + } + }, + "ProjectBatchServiceRoleF97A1CFB": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "ProjectBatchServiceRoleDefaultPolicy5E00842B": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codebuild:RetryBuild", + "codebuild:StartBuild", + "codebuild:StopBuild" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ProjectC78D97AD", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "ProjectBatchServiceRoleDefaultPolicy5E00842B", + "Roles": [ + { + "Ref": "ProjectBatchServiceRoleF97A1CFB" + } + ] + } + }, + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codebuild:BatchGetBuildBatches", + "codebuild:StartBuildBatch", + "codebuild:StopBuildBatch" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ProjectC78D97AD", + "Arn" + ] + } + }, + { + "Action": [ + "events:DescribeRule", + "events:PutRule", + "events:PutTargets" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":events:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"bar\":\"SomeValue\"},\"Next\":\"buildTask1\"},\"buildTask1\":{\"Next\":\"buildTask2\",\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::codebuild:startBuildBatch\",\"Parameters\":{\"ProjectName\":\"", + { + "Ref": "ProjectC78D97AD" + }, + "\",\"EnvironmentVariablesOverride\":[{\"Name\":\"test\",\"Type\":\"PLAINTEXT\",\"Value\":\"testValue\"}]}},\"buildTask2\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::codebuild:startBuildBatch.sync\",\"Parameters\":{\"ProjectName\":\"", + { + "Ref": "ProjectC78D97AD" + }, + "\",\"EnvironmentVariablesOverride\":[{\"Name\":\"test\",\"Type\":\"PLAINTEXT\",\"Value\":\"testValue\"}]}}}}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "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/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets.json new file mode 100644 index 0000000000000..bb963bcd7c8ab --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "StartBuildBatchIntegDefaultTestDeployAssert142C169A.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/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/StartBuildBatchIntegDefaultTestDeployAssert142C169A.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/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/integ.json new file mode 100644 index 0000000000000..fa32ffe5a59f1 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "StartBuildBatchInteg/DefaultTest": { + "stacks": [ + "StartBuildBatch" + ], + "assertionStack": "StartBuildBatchInteg/DefaultTest/DeployAssert", + "assertionStackName": "StartBuildBatchIntegDefaultTestDeployAssert142C169A" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/manifest.json new file mode 100644 index 0000000000000..22303e0a7c37c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/manifest.json @@ -0,0 +1,155 @@ +{ + "version": "36.0.0", + "artifacts": { + "StartBuildBatch.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "StartBuildBatch.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "StartBuildBatch": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "StartBuildBatch.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "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}/5a4a7364d62c5bab6b3ec3ccfa6d371f59724308214a3fd5da99da666d1c943a.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "StartBuildBatch.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": [ + "StartBuildBatch.assets" + ], + "metadata": { + "/StartBuildBatch/Project/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ProjectRole4CCB274E" + } + ], + "/StartBuildBatch/Project/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ProjectRoleDefaultPolicy7F29461B" + } + ], + "/StartBuildBatch/Project/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ProjectC78D97AD" + } + ], + "/StartBuildBatch/Project/BatchServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ProjectBatchServiceRoleF97A1CFB" + } + ], + "/StartBuildBatch/Project/BatchServiceRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ProjectBatchServiceRoleDefaultPolicy5E00842B" + } + ], + "/StartBuildBatch/StateMachine/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleB840431D" + } + ], + "/StartBuildBatch/StateMachine/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachineRoleDefaultPolicyDF1E6607" + } + ], + "/StartBuildBatch/StateMachine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "StateMachine2E01A3A5" + } + ], + "/StartBuildBatch/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/StartBuildBatch/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "StartBuildBatch" + }, + "StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "StartBuildBatchIntegDefaultTestDeployAssert142C169A": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "StartBuildBatchIntegDefaultTestDeployAssert142C169A.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "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": [ + "StartBuildBatchIntegDefaultTestDeployAssert142C169A.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": [ + "StartBuildBatchIntegDefaultTestDeployAssert142C169A.assets" + ], + "metadata": { + "/StartBuildBatchInteg/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/StartBuildBatchInteg/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "StartBuildBatchInteg/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/tree.json new file mode 100644 index 0000000000000..b9568a47cac9f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.js.snapshot/tree.json @@ -0,0 +1,613 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "StartBuildBatch": { + "id": "StartBuildBatch", + "path": "StartBuildBatch", + "children": { + "Project": { + "id": "Project", + "path": "StartBuildBatch/Project", + "children": { + "Role": { + "id": "Role", + "path": "StartBuildBatch/Project/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "StartBuildBatch/Project/Role/ImportRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/Project/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "StartBuildBatch/Project/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/Project/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + }, + ":*" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + } + ] + ] + } + ] + }, + { + "Action": [ + "codebuild:BatchPutCodeCoverages", + "codebuild:BatchPutTestCases", + "codebuild:CreateReport", + "codebuild:CreateReportGroup", + "codebuild:UpdateReport" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codebuild:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "ProjectC78D97AD" + }, + "-*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "ProjectRoleDefaultPolicy7F29461B", + "roles": [ + { + "Ref": "ProjectRole4CCB274E" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/Project/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CodeBuild::Project", + "aws:cdk:cloudformation:props": { + "artifacts": { + "type": "NO_ARTIFACTS" + }, + "buildBatchConfig": { + "serviceRole": { + "Fn::GetAtt": [ + "ProjectBatchServiceRoleF97A1CFB", + "Arn" + ] + } + }, + "cache": { + "type": "NO_CACHE" + }, + "encryptionKey": "alias/aws/s3", + "environment": { + "type": "LINUX_CONTAINER", + "image": "aws/codebuild/standard:5.0", + "imagePullCredentialsType": "CODEBUILD", + "privilegedMode": false, + "computeType": "BUILD_GENERAL1_SMALL" + }, + "name": "MyTestProject", + "serviceRole": { + "Fn::GetAtt": [ + "ProjectRole4CCB274E", + "Arn" + ] + }, + "source": { + "type": "NO_SOURCE", + "buildSpec": "version: 0.2\nbatch:\n fast-fail: true\n build-list:\n - identifier: linux_small\n env:\n compute-type: BUILD_GENERAL1_SMALL\n image: aws/codebuild/standard:5.0\n type: LINUX_CONTAINER\n variables:\n key1: value1\n buildspec: |-\n version: 0.2\n phases:\n build:\n commands:\n - echo \"Hello, from small!\"\n - identifier: linux_medium\n env:\n compute-type: BUILD_GENERAL1_MEDIUM\n image: aws/codebuild/standard:4.0\n type: LINUX_CONTAINER\n variables:\n key2: value2\n buildspec: |-\n version: 0.2\n phases:\n build:\n commands:\n - echo \"Hello, from medium!\"\n" + }, + "timeoutInMinutes": 60 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_codebuild.CfnProject", + "version": "0.0.0" + } + }, + "BatchServiceRole": { + "id": "BatchServiceRole", + "path": "StartBuildBatch/Project/BatchServiceRole", + "children": { + "ImportBatchServiceRole": { + "id": "ImportBatchServiceRole", + "path": "StartBuildBatch/Project/BatchServiceRole/ImportBatchServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/Project/BatchServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "StartBuildBatch/Project/BatchServiceRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/Project/BatchServiceRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "codebuild:RetryBuild", + "codebuild:StartBuild", + "codebuild:StopBuild" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ProjectC78D97AD", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "ProjectBatchServiceRoleDefaultPolicy5E00842B", + "roles": [ + { + "Ref": "ProjectBatchServiceRoleF97A1CFB" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_codebuild.Project", + "version": "0.0.0" + } + }, + "buildTask1": { + "id": "buildTask1", + "path": "StartBuildBatch/buildTask1", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.CodeBuildStartBuildBatch", + "version": "0.0.0" + } + }, + "buildTask2": { + "id": "buildTask2", + "path": "StartBuildBatch/buildTask2", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.CodeBuildStartBuildBatch", + "version": "0.0.0" + } + }, + "Start": { + "id": "Start", + "path": "StartBuildBatch/Start", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.Pass", + "version": "0.0.0" + } + }, + "StateMachine": { + "id": "StateMachine", + "path": "StartBuildBatch/StateMachine", + "children": { + "Role": { + "id": "Role", + "path": "StartBuildBatch/StateMachine/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "StartBuildBatch/StateMachine/Role/ImportRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/StateMachine/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": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "StartBuildBatch/StateMachine/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/StateMachine/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "codebuild:BatchGetBuildBatches", + "codebuild:StartBuildBatch", + "codebuild:StopBuildBatch" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ProjectC78D97AD", + "Arn" + ] + } + }, + { + "Action": [ + "events:DescribeRule", + "events:PutRule", + "events:PutTargets" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":events:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "StateMachineRoleDefaultPolicyDF1E6607", + "roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "StartBuildBatch/StateMachine/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::StepFunctions::StateMachine", + "aws:cdk:cloudformation:props": { + "definitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"bar\":\"SomeValue\"},\"Next\":\"buildTask1\"},\"buildTask1\":{\"Next\":\"buildTask2\",\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::codebuild:startBuildBatch\",\"Parameters\":{\"ProjectName\":\"", + { + "Ref": "ProjectC78D97AD" + }, + "\",\"EnvironmentVariablesOverride\":[{\"Name\":\"test\",\"Type\":\"PLAINTEXT\",\"Value\":\"testValue\"}]}},\"buildTask2\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::codebuild:startBuildBatch.sync\",\"Parameters\":{\"ProjectName\":\"", + { + "Ref": "ProjectC78D97AD" + }, + "\",\"EnvironmentVariablesOverride\":[{\"Name\":\"test\",\"Type\":\"PLAINTEXT\",\"Value\":\"testValue\"}]}}}}" + ] + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "StartBuildBatch/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "StartBuildBatch/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "StartBuildBatchInteg": { + "id": "StartBuildBatchInteg", + "path": "StartBuildBatchInteg", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "StartBuildBatchInteg/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "StartBuildBatchInteg/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "StartBuildBatchInteg/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "StartBuildBatchInteg/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "StartBuildBatchInteg/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.ts new file mode 100644 index 0000000000000..9556b37f07af8 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/codebuild/integ.start-build-batch.ts @@ -0,0 +1,94 @@ +import * as codebuild from 'aws-cdk-lib/aws-codebuild'; +import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; +import * as cdk from 'aws-cdk-lib'; +import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +class TestStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props: cdk.StackProps = {}) { + super(scope, id, props); + + const project = new codebuild.Project(this, 'Project', { + projectName: 'MyTestProject', + environment: { + buildImage: codebuild.LinuxBuildImage.STANDARD_5_0, + }, + timeout: cdk.Duration.hours(1), + buildSpec: codebuild.BuildSpec.fromObjectToYaml({ + version: 0.2, + batch: { + 'fast-fail': true, + 'build-list': [ + { + identifier: 'linux_small', + env: { + 'compute-type': 'BUILD_GENERAL1_SMALL', + 'image': 'aws/codebuild/standard:5.0', + 'type': 'LINUX_CONTAINER', + 'variables': { + key1: 'value1', + }, + }, + buildspec: 'version: 0.2\nphases:\n build:\n commands:\n - echo "Hello, from small!"', + }, + { + identifier: 'linux_medium', + env: { + 'compute-type': 'BUILD_GENERAL1_MEDIUM', + 'image': 'aws/codebuild/standard:4.0', + 'type': 'LINUX_CONTAINER', + 'variables': { + key2: 'value2', + }, + }, + buildspec: 'version: 0.2\nphases:\n build:\n commands:\n - echo "Hello, from medium!"', + }, + ], + }, + }), + }); + const buildconfig = project.enableBatchBuilds(); + + if (buildconfig == null) { + throw new Error('Batch builds not enabled'); + } + + const startBuildBatch1 = new tasks.CodeBuildStartBuildBatch(this, 'buildTask1', { + project, + integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE, + environmentVariablesOverride: { + test: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'testValue', + }, + }, + }); + + const startBuildBatch2 = new tasks.CodeBuildStartBuildBatch(this, 'buildTask2', { + project, + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + environmentVariablesOverride: { + test: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'testValue', + }, + }, + }); + + const definition = new sfn.Pass(this, 'Start', { + result: sfn.Result.fromObject({ bar: 'SomeValue' }), + }).next(startBuildBatch1).next(startBuildBatch2); + + new sfn.StateMachine(this, 'StateMachine', { + definition, + }); + } +} + +const app = new cdk.App(); +const stack = new TestStack(app, 'StartBuildBatch'); +new IntegTest(app, 'StartBuildBatchInteg', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md index c19d860f46892..7d6d69da5df58 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md @@ -386,6 +386,45 @@ const task = new tasks.CodeBuildStartBuild(this, 'Task', { }); ``` +### StartBuildBatch + +[StartBuildBatch](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuildBatch.html) starts a batch CodeBuild for a project by project name. +It is necessary to enable the batch build feature in the CodeBuild project. + +```ts +import * as codebuild from 'aws-cdk-lib/aws-codebuild'; + +const project = new codebuild.Project(this, 'Project', { + projectName: 'MyTestProject', + buildSpec: codebuild.BuildSpec.fromObjectToYaml({ + version: 0.2, + batch: { + 'build-list': [ + { + identifier: 'id', + buildspec: 'version: 0.2\nphases:\n build:\n commands:\n - echo "Hello, from small!"', + }, + ], + }, + }), +}); +project.enableBatchBuilds(); + +const task = new tasks.CodeBuildStartBuildBatch(this, 'buildBatchTask', { + project, + integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE, + environmentVariablesOverride: { + test: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'testValue', + }, + }, +}); +``` + +**Note**: `enableBatchBuilds()` will do nothing for imported projects. +If you are using an imported project, you must ensure that the project is already configured for batch builds. + ## DynamoDB You can call DynamoDB APIs from a `Task` state. diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts new file mode 100644 index 0000000000000..c08c3299b9107 --- /dev/null +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts @@ -0,0 +1,127 @@ +import { Construct } from 'constructs'; +import * as codebuild from '../../../aws-codebuild'; +import * as iam from '../../../aws-iam'; +import * as sfn from '../../../aws-stepfunctions'; +import * as cdk from '../../../core'; +import { integrationResourceArn, validatePatternSupported } from '../private/task-utils'; + +/** + * Properties for CodeBuildStartBuildBatch + */ +export interface CodeBuildStartBuildBatchProps extends sfn.TaskStateBaseProps { + /** + * CodeBuild project to start + */ + readonly project: codebuild.IProject; + + /** + * A set of environment variables to be used for this build only. + * + * @default - the latest environment variables already defined in the build project. + */ + readonly environmentVariablesOverride?: { [name: string]: codebuild.BuildEnvironmentVariable }; +} + +/** + * Start a CodeBuild BatchBuild as a task + * + * @see https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuildBatch.html + */ +export class CodeBuildStartBuildBatch extends sfn.TaskStateBase { + private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ + sfn.IntegrationPattern.REQUEST_RESPONSE, + sfn.IntegrationPattern.RUN_JOB, + ]; + + protected readonly taskMetrics?: sfn.TaskMetricsConfig; + protected readonly taskPolicies?: iam.PolicyStatement[]; + + private readonly integrationPattern: sfn.IntegrationPattern; + + constructor(scope: Construct, id: string, private readonly props: CodeBuildStartBuildBatchProps) { + super(scope, id, props); + this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; + + validatePatternSupported(this.integrationPattern, CodeBuildStartBuildBatch.SUPPORTED_INTEGRATION_PATTERNS); + + this.taskMetrics = { + metricPrefixSingular: 'CodeBuildProject', + metricPrefixPlural: 'CodeBuildProjects', + metricDimensions: { + ProjectArn: this.props.project.projectArn, + }, + }; + + this.taskPolicies = this.configurePolicyStatements(); + } + + /** + * Configure the necessary permissions to invoke the CodeBuild StartBuildBatch API + * + * @see https://docs.aws.amazon.com/step-functions/latest/dg/codebuild-iam.html#codebuild-iam-startbuildbatch + */ + private configurePolicyStatements(): iam.PolicyStatement[] { + let policyStatements: iam.PolicyStatement[]; + + switch (this.integrationPattern) { + case sfn.IntegrationPattern.RUN_JOB: + policyStatements = [ + new iam.PolicyStatement({ + resources: [this.props.project.projectArn], + actions: [ + 'codebuild:StartBuildBatch', + 'codebuild:StopBuildBatch', + 'codebuild:BatchGetBuildBatches', + ], + }), + new iam.PolicyStatement({ + actions: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'], + resources: [ + cdk.Stack.of(this).formatArn({ + service: 'events', + resource: 'rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule', + }), + ], + }), + ]; + break; + case sfn.IntegrationPattern.REQUEST_RESPONSE: + policyStatements = [ + new iam.PolicyStatement({ + resources: [this.props.project.projectArn], + actions: ['codebuild:StartBuildBatch'], + }), + ]; + break; + default: + throw new Error(`Unsupported integration pattern: ${this.integrationPattern}`); + } + + return policyStatements; + } + + /** + * Provides the CodeBuild StartBuild service integration task configuration + * + * @internal + */ + protected _renderTask(): any { + return { + Resource: integrationResourceArn('codebuild', 'startBuildBatch', this.integrationPattern), + Parameters: sfn.FieldUtils.renderObject({ + ProjectName: this.props.project.projectName, + EnvironmentVariablesOverride: this.props.environmentVariablesOverride + ? this.serializeEnvVariables(this.props.environmentVariablesOverride) + : undefined, + }), + }; + } + + private serializeEnvVariables(environmentVariables: { [name: string]: codebuild.BuildEnvironmentVariable }) { + return Object.keys(environmentVariables).map(name => ({ + Name: name, + Type: environmentVariables[name].type || codebuild.BuildEnvironmentVariableType.PLAINTEXT, + Value: environmentVariables[name].value, + })); + } +} diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts index 575464d22dcf0..1021c7e9950a6 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts @@ -42,6 +42,7 @@ export * from './dynamodb/update-item'; export * from './dynamodb/delete-item'; export * from './dynamodb/shared-types'; export * from './codebuild/start-build'; +export * from './codebuild/start-build-batch'; export * from './athena/start-query-execution'; export * from './athena/stop-query-execution'; export * from './athena/get-query-execution'; diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/codebuild/start-build-batch.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/codebuild/start-build-batch.test.ts new file mode 100644 index 0000000000000..15d1d3f71ded3 --- /dev/null +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/codebuild/start-build-batch.test.ts @@ -0,0 +1,215 @@ +import { Template, Match } from '../../../assertions'; +import * as codebuild from '../../../aws-codebuild'; +import * as sfn from '../../../aws-stepfunctions'; +import * as cdk from '../../../core'; +import { CodeBuildStartBuildBatch } from '../../lib'; + +let stack: cdk.Stack; +let codebuildProject: codebuild.Project; + +beforeEach(() => { + // GIVEN + stack = new cdk.Stack(); + + codebuildProject = new codebuild.Project(stack, 'Project', { + projectName: 'MyTestProject', + buildSpec: codebuild.BuildSpec.fromObjectToYaml({ + version: '0.2', + batch: { + 'fast-fail': true, + 'build-list': [ + { + identifier: 'id', + buildspec: 'version: 0.2\nphases:\n build:\n commands:\n - echo "Hello, CodeBuild!"', + }, + ], + }, + }), + }); + codebuildProject.enableBatchBuilds(); +}); + +test('only the required parameters', () => { + // WHEN + const task = new CodeBuildStartBuildBatch(stack, 'Task', { + project: codebuildProject, + }); + new sfn.StateMachine(stack, 'StateMachine', { + definitionBody: sfn.DefinitionBody.fromChainable(task), + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::codebuild:startBuildBatch', + ], + ], + }, + End: true, + Parameters: { + ProjectName: { + Ref: 'ProjectC78D97AD', + }, + }, + }); + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [{ + Action: 'codebuild:StartBuildBatch', + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': ['ProjectC78D97AD', 'Arn'], + }, + }], + }, + }); +}); + +test('supports tokens', () => { + // WHEN + const task = new CodeBuildStartBuildBatch(stack, 'Task', { + project: codebuildProject, + environmentVariablesOverride: { + ZONE: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: sfn.JsonPath.stringAt('$.envVariables.zone'), + }, + }, + }); + new sfn.StateMachine(stack, 'StateMachine', { + definitionBody: sfn.DefinitionBody.fromChainable(task), + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::codebuild:startBuildBatch', + ], + ], + }, + End: true, + Parameters: { + ProjectName: { + Ref: 'ProjectC78D97AD', + }, + EnvironmentVariablesOverride: [ + { + 'Name': 'ZONE', + 'Type': codebuild.BuildEnvironmentVariableType.PLAINTEXT, + 'Value.$': '$.envVariables.zone', + }, + ], + }, + }); +}); + +test('with all the parameters', () => { + // WHEN + const task = new CodeBuildStartBuildBatch(stack, 'Task', { + project: codebuildProject, + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + environmentVariablesOverride: { + env: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'prod', + }, + }, + }); + new sfn.StateMachine(stack, 'StateMachine', { + definitionBody: sfn.DefinitionBody.fromChainable(task), + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::codebuild:startBuildBatch.sync', + ], + ], + }, + End: true, + Parameters: { + ProjectName: { + Ref: 'ProjectC78D97AD', + }, + EnvironmentVariablesOverride: [ + { + Name: 'env', + Type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + Value: 'prod', + }, + ], + }, + }); + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyDocument: { + Statement: Match.arrayWith([ + { + Action: ['codebuild:StartBuildBatch', 'codebuild:StopBuildBatch', 'codebuild:BatchGetBuildBatches'], + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': ['ProjectC78D97AD', 'Arn'], + }, + }, + { + Action: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'], + Effect: 'Allow', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':events:', + { + Ref: 'AWS::Region', + }, + ':', + { + Ref: 'AWS::AccountId', + }, + ':rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule', + ], + ], + }, + }, + ]), + }, + }); +}); + +test('throw error when WAIT_FOR_TASK_TOKEN is supplied as service integration pattern', () => { + expect(() => { + new CodeBuildStartBuildBatch(stack, 'Task', { + project: codebuildProject, + integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + }); + }).toThrow( + /Unsupported service integration pattern. Supported Patterns: REQUEST_RESPONSE,RUN_JOB. Received: WAIT_FOR_TASK_TOKEN/, + ); +});