Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stepfunctions-tasks): add emr-containers support for calling CreateVirtualCluster, DeleteVirtualCluster, and StartJobRun #15262

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d3c1ce0
fix(core): parsing an ARN with a slash after a colon in the resource …
skinny85 Jun 17, 2021
e37d4dc
Merge branch 'master' into fix/arn-parse-slash-after-colon
mergify[bot] Jun 21, 2021
f1ed884
feat(stepfunctions-tasks): Initial commit with base-types definition,…
Jun 22, 2021
6da8b96
Finished comment documentation and changed props
Jun 28, 2021
e4af04c
feat(stepfunctions-tasks): Initial commit with base-types definition,…
Jun 22, 2021
0f2af94
Merge branch 'containers' of https://github.com/matthewsvu/aws-cdk in…
Jun 30, 2021
ed7ec9b
Finished writing unit tests for Create and DeleteVirtualCluster
Jul 2, 2021
478f2c8
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
e31b783
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
79efa08
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
301730f
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
43786fa
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
0b76c61
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
ac9bcfe
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
2329255
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/st…
matthewsvu Jul 4, 2021
7f72556
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/ba…
matthewsvu Jul 4, 2021
e60251a
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 4, 2021
6505acc
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/de…
matthewsvu Jul 4, 2021
4da1cf7
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/de…
matthewsvu Jul 6, 2021
338078d
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/st…
matthewsvu Jul 6, 2021
8685329
StartJobRun and CreateVirtualCluster API changes
Jul 9, 2021
6c4d416
removed modified file from PR
Jul 9, 2021
ebbdc16
removed package-lock.json + package.json from PR
Jul 9, 2021
b907327
More StartJobRun api modification
Jul 10, 2021
01338ce
Added changes to user facing api structure to start-job-run, base-typ…
Jul 28, 2021
d5b4858
Added package dependencies for logs, awscli, and custom-resources
Jul 28, 2021
3593c76
Added README, removed base-types, added error validation
Jul 30, 2021
f2e4897
fix readme
Jul 30, 2021
acbd8e8
README formatting issue correction
Jul 30, 2021
2eb8cd4
Added README, removed base-types, added error validation
Jul 30, 2021
b005182
Merge branch 'containers' of https://github.com/matthewsvu/aws-cdk in…
Jul 30, 2021
37da06d
README linting
Jul 30, 2021
1f5d518
Update packages/@aws-cdk/aws-stepfunctions-tasks/README.md
matthewsvu Jul 31, 2021
97b419a
Update packages/@aws-cdk/aws-stepfunctions-tasks/README.md
matthewsvu Jul 31, 2021
645e54b
Update packages/@aws-cdk/aws-stepfunctions-tasks/README.md
matthewsvu Jul 31, 2021
304a759
Update packages/@aws-cdk/aws-stepfunctions-tasks/README.md
matthewsvu Jul 31, 2021
9045233
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
cb9c9ab
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
de896fc
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
ef6668a
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
d798fe0
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
72d2b34
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
fb85f00
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Jul 31, 2021
0fa6738
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/de…
matthewsvu Jul 31, 2021
e3946bb
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/de…
matthewsvu Jul 31, 2021
08ae7e8
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/de…
matthewsvu Jul 31, 2021
b162389
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/st…
matthewsvu Jul 31, 2021
b3a712b
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/st…
matthewsvu Jul 31, 2021
674da28
Apply suggestions from code review
matthewsvu Aug 2, 2021
0af25ae
Merge branch 'containers' of https://github.com/matthewsvu/aws-cdk in…
Aug 3, 2021
bd0e168
Apply suggestions from code review
Aug 3, 2021
deb9a9c
README example changes, execution-role policy changes, lambda changes
Aug 5, 2021
0a26ffb
Fix merge conflicts with remote containers
Aug 5, 2021
223f4de
Apply suggestions from code review
matthewsvu Aug 7, 2021
b5201d4
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/st…
matthewsvu Aug 9, 2021
b7b35ec
Added unit tests to start-job-run, adjust iam scope, added to README
Aug 13, 2021
1a74fba
Minor changes to README, Fixed Error validation, completed start-job-…
Aug 17, 2021
50df69b
minor changes to tests
Aug 17, 2021
9d8f64e
Apply suggestions from code review
matthewsvu Aug 17, 2021
7bd82cd
Unit test changes from PR
Aug 18, 2021
1073925
Minor unit test additions
Aug 18, 2021
842fbdc
Merge branch 'master', commit 'e37d4dc63ab4b187cf8d1c7799838efc327cfa…
Aug 18, 2021
6098822
Cleaning up tests
Aug 18, 2021
7eec75c
Apply suggestions from code review
matthewsvu Aug 19, 2021
f14b4ca
Apply suggestions from code review
matthewsvu Aug 19, 2021
1053102
Apply suggestions from code review
matthewsvu Aug 19, 2021
f66dea5
Merge branch 'master' into containers
matthewsvu Aug 19, 2021
b09274d
Merge branch 'master' of https://github.com/matthewsvu/aws-cdk into c…
Aug 19, 2021
fcd20f3
Fix merge conflicts and modified tests
Aug 19, 2021
847dcf8
Unit tests revision, PR comment revisions
Aug 20, 2021
0189281
Merge branch 'containers' of https://github.com/matthewsvu/aws-cdk in…
Aug 20, 2021
55c60ce
Apply suggestions from code review
matthewsvu Aug 20, 2021
38e51e6
Apply suggestions from code review
matthewsvu Aug 20, 2021
a0640ce
Update packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/cr…
matthewsvu Aug 20, 2021
ef49003
PR comment changes to tests and Name Parameters
Aug 20, 2021
9a868a1
Merge branch 'containers' of https://github.com/matthewsvu/aws-cdk in…
Aug 20, 2021
a4424a0
Apply suggestions from code review
matthewsvu Oct 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class EmrContainersEksCreateVirtualCluster extends sfn.TaskStateBase {
return {
Resource: integrationResourceArn('emr-containers', 'createVirtualCluster', this.integrationPattern),
Parameters: sfn.FieldUtils.renderObject({
Name: this.props.virtualClusterName ?? `${sfn.JsonPath.stringAt('$$.Execution.Name')}`,
Name: this.props.virtualClusterName ?? sfn.JsonPath.stringAt('States.Format(\'{}/{}\', $$.Execution.Name, $$.StateMachine.Name)'),
matthewsvu marked this conversation as resolved.
Show resolved Hide resolved
ContainerProvider: {
Id: this.props.eksCluster.clusterName,
Info: {
Expand All @@ -125,15 +125,11 @@ export class EmrContainersEksCreateVirtualCluster extends sfn.TaskStateBase {
},
Type: ContainerProviderTypes.EKS,
},
...(this.props.tags ? this.renderTags(this.props.tags) : undefined),
Tags: this.props.tags,
}),
};
};

private renderTags(tags?: { [key: string]: any } | undefined): { [key: string]: any } {
return tags ? { Tags: Object.entries(tags).map(([key, value]) => ({ Key: key, Value: value })) } : {};
}

private createPolicyStatements(): iam.PolicyStatement[] {
return [
new iam.PolicyStatement({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface EmrContainersStartJobRunProps extends sfn.TaskStateBaseProps {
/**
* The ID of the virtual cluster where the job will be run
*/
readonly virtualClusterId: sfn.TaskInput;
readonly virtualCluster: VirtualClusterInput;

/**
* The name of the job run.
Expand Down Expand Up @@ -119,8 +119,8 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
}

if (props.jobDriver.sparkSubmitJobDriver?.entryPointArguments
&& (typeof props.jobDriver.sparkSubmitJobDriver.entryPointArguments.value === 'string'
&& !sfn.JsonPath.isEncodedJsonPath(props.jobDriver.sparkSubmitJobDriver.entryPointArguments.value))) {
&& typeof props.jobDriver.sparkSubmitJobDriver.entryPointArguments.value === 'string'
&& !sfn.JsonPath.isEncodedJsonPath(props.jobDriver.sparkSubmitJobDriver.entryPointArguments.value)) {
throw new Error(`Entry point arguments must be a string array. Received ${typeof props.jobDriver.sparkSubmitJobDriver.entryPointArguments.value}.`);
}

Expand All @@ -143,7 +143,7 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
}

if (props.executionRole === undefined
&& sfn.JsonPath.isEncodedJsonPath(props.virtualClusterId.value)) {
&& sfn.JsonPath.isEncodedJsonPath(props.virtualCluster.id)) {
throw new Error('Execution role cannot be undefined when the virtual cluster ID is not a concrete value. Provide an execution role with the correct trust policy');
}

Expand All @@ -164,7 +164,7 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
return {
Resource: integrationResourceArn('emr-containers', 'startJobRun', this.integrationPattern),
Parameters: sfn.FieldUtils.renderObject({
VirtualClusterId: this.props.virtualClusterId.value,
VirtualClusterId: this.props.virtualCluster.id,
Name: this.props.jobName,
ExecutionRoleArn: this.role.roleArn,
ReleaseLabel: this.props.releaseLabel.label,
Expand All @@ -177,20 +177,20 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
},
ConfigurationOverrides: {
ApplicationConfiguration: cdk.listMapper(this.applicationConfigPropertyToJson)(this.props.applicationConfig),
MonitoringConfiguration: this.props.monitoring ? {
MonitoringConfiguration: {
CloudWatchMonitoringConfiguration: this.logGroup ? {
LogGroupName: this.logGroup?.logGroupName, // automatically generated name https://docs.aws.amazon.com/cdk/api/latest/typescript/api/aws-logs/loggroup.html#aws_logs_LogGroup_synopsis
LogStreamNamePrefix: this.props.monitoring?.logStreamNamePrefix,
LogGroupName: this.logGroup.logGroupName,
LogStreamNamePrefix: this.props.monitoring!.logStreamNamePrefix,
} : undefined,
PersistentAppUI: (this.props.monitoring?.persistentAppUI === false)
? 'DISABLED'
: 'ENABLED',
S3MonitoringConfiguration: this.logBucket ? {
LogUri: this.logBucket?.s3UrlForObject(), // automatically generated unique name https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html#bucketname
LogUri: this.logBucket.s3UrlForObject(),
} : undefined,
} : undefined,
},
},
...(this.props.tags ? this.renderTags(this.props.tags) : undefined),
Tags: this.props.tags,
}),
};
}
Expand Down Expand Up @@ -229,10 +229,6 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
return Array.isArray(value) && value.every(item => typeof item === 'string');
}

private renderTags(tags?: { [key: string]: any } | undefined): { [key: string]: any } {
return tags ? { Tags: Object.entries(tags).map(([key, value]) => ({ Key: key, Value: value })) } : {};
}

// https://docs.aws.amazon.com/emr/latest/EMR-on-EKS-DevelopmentGuide/creating-job-execution-role.html
private createJobExecutionRole(): iam.Role {
const jobExecutionRole = new iam.Role(this, 'Job-Execution-Role', {
Expand Down Expand Up @@ -296,7 +292,7 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
service: 'EMRcontainers',
action: 'describeVirtualCluster',
parameters: {
id: this.props.virtualClusterId.value,
id: this.props.virtualCluster.id,
},
outputPaths: ['virtualCluster.containerProvider.info.eksInfo.namespace', 'virtualCluster.containerProvider.id'],
physicalResourceId: cr.PhysicalResourceId.of('id'),
Expand Down Expand Up @@ -360,7 +356,7 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
arnFormat: cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME,
service: 'emr-containers',
resource: 'virtualclusters',
resourceName: sfn.JsonPath.isEncodedJsonPath(this.props.virtualClusterId.value) ? '*' : this.props.virtualClusterId.value, // Need wild card for dynamic start job run https://docs.aws.amazon.com/step-functions/latest/dg/emr-eks-iam.html
resourceName: sfn.JsonPath.isEncodedJsonPath(this.props.virtualCluster.id) ? '*' : this.props.virtualCluster.id, // Need wild card for dynamic start job run https://docs.aws.amazon.com/step-functions/latest/dg/emr-eks-iam.html
}),
],
actions: ['emr-containers:StartJobRun'],
Expand All @@ -380,7 +376,7 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
arnFormat: cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME,
service: 'emr-containers',
resource: 'virtualclusters',
resourceName: sfn.JsonPath.isEncodedJsonPath(this.props.virtualClusterId.value) ? '*' : `${this.props.virtualClusterId.value}/jobruns/*`, // Need wild card for dynamic start job run https://docs.aws.amazon.com/step-functions/latest/dg/emr-eks-iam.html
resourceName: sfn.JsonPath.isEncodedJsonPath(this.props.virtualCluster.id) ? '*' : `${this.props.virtualCluster.id}/jobruns/*`, // Need wild card for dynamic start job run https://docs.aws.amazon.com/step-functions/latest/dg/emr-eks-iam.html
}),
],
actions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
// WHEN
const task = new EmrContainersEksCreateVirtualCluster(stack, 'Task', {
eksCluster: EksClusterInput.fromTaskInput(sfn.TaskInput.fromText(clusterId)),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

new sfn.StateMachine(stack, 'SM', {
Expand All @@ -42,7 +41,7 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
},
End: true,
Parameters: {
'Name.$': '$$.Execution.Name',
'Name.$': "States.Format('{}/{}', $$.Execution.Name, $$.StateMachine.Name)",
'ContainerProvider': {
matthewsvu marked this conversation as resolved.
Show resolved Hide resolved
Id: clusterId,
Info: {
Expand Down Expand Up @@ -80,7 +79,6 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
Namespace: 'namespace',
},
},
Type: 'EKS',
},
},
});
Expand All @@ -89,23 +87,14 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
test('clusterId from payload', () => {
// WHEN
const task = new EmrContainersEksCreateVirtualCluster(stack, 'Task', {
virtualClusterName: emrContainersVirtualClusterName,
eksCluster: EksClusterInput.fromTaskInput(sfn.TaskInput.fromJsonPathAt('$.ClusterId')),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

// THEN
expect(stack.resolve(task.toStateJson())).toMatchObject({
Parameters: {
Name: emrContainersVirtualClusterName,
ContainerProvider: {
'Id.$': '$.ClusterId',
'Info': {
EksInfo: {
Namespace: 'default',
},
},
'Type': 'EKS',
},
},
});
Expand All @@ -118,25 +107,16 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
});

const task = new EmrContainersEksCreateVirtualCluster(stack, 'Task', {
virtualClusterName: emrContainersVirtualClusterName,
eksCluster: EksClusterInput.fromCluster(eksCluster),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

// THEN
expect(stack.resolve(task.toStateJson())).toMatchObject({
Parameters: {
Name: emrContainersVirtualClusterName,
ContainerProvider: {
Id: {
Ref: 'EKSClusterEDAD5FD1',
},
Info: {
EksInfo: {
Namespace: 'default',
},
},
Type: 'EKS',
},
},
});
Expand All @@ -146,11 +126,9 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
// WHEN
const task = new EmrContainersEksCreateVirtualCluster(stack, 'Task', {
eksCluster: EksClusterInput.fromTaskInput(sfn.TaskInput.fromText(clusterId)),
virtualClusterName: emrContainersVirtualClusterName,
tags: {
key: 'value',
},
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

new sfn.StateMachine(stack, 'SM', {
Expand All @@ -160,20 +138,9 @@ describe('Invoke emr-containers CreateVirtualCluster with ', () => {
// THEN
expect(stack.resolve(task.toStateJson())).toMatchObject({
Parameters: {
Name: emrContainersVirtualClusterName,
ContainerProvider: {
Id: clusterId,
Info: {
EksInfo: {
Namespace: 'default',
},
},
Type: 'EKS',
Tags: {
key: 'value',
},
Tags: [{
Key: 'key',
Value: 'value',
}],
},
});
});
Expand All @@ -184,7 +151,6 @@ test('Permitted role actions included for CreateVirtualCluster if service integr
const task = new EmrContainersEksCreateVirtualCluster(stack, 'Task', {
virtualClusterName: emrContainersVirtualClusterName,
eksCluster: EksClusterInput.fromTaskInput(sfn.TaskInput.fromText(clusterId)),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

new sfn.StateMachine(stack, 'SM', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('Invoke EMR Containers Delete Virtual cluster with ', () => {
// WHEN
const task = new EmrContainersDeleteVirtualCluster(stack, 'Task', {
virtualClusterId: sfn.TaskInput.fromText(virtualClusterId),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

// THEN
Expand Down Expand Up @@ -74,7 +73,6 @@ describe('Invoke EMR Containers Delete Virtual cluster with ', () => {
// WHEN
const task = new EmrContainersDeleteVirtualCluster(stack, 'Task', {
virtualClusterId: sfn.TaskInput.fromJsonPathAt('$.VirtualClusterId'),
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
});

// THEN
Expand All @@ -91,7 +89,6 @@ describe('Valid policy statements and resources are passed ', () => {
// WHEN
const task = new EmrContainersDeleteVirtualCluster(stack, 'Task', {
virtualClusterId: sfn.TaskInput.fromText(virtualClusterId),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

new sfn.StateMachine(stack, 'SM', {
Expand Down

This file was deleted.

Loading