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 step functions task to run glue job #6258

Merged
merged 21 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9d89269
feat(stepfunctions-tasks): add step functions task to run glue job
BenChaimberg Jan 14, 2020
646f323
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 21, 2020
402a76c
cleanup constructor properties, add integration test
BenChaimberg Feb 21, 2020
4232e96
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 24, 2020
56d8371
remove job run ID from props, update default prop descriptions
BenChaimberg Feb 24, 2020
f4285b3
add s3 assets package to module
BenChaimberg Feb 24, 2020
442f2cd
fix linting errors
BenChaimberg Feb 24, 2020
48fc836
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 24, 2020
876e05e
clean up documentation, add links to docs and glue task example
BenChaimberg Feb 26, 2020
2d9c360
add verification step to integration step, ensure job succeeds
BenChaimberg Feb 26, 2020
004ebd7
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 26, 2020
bf5f39a
update expected integration test stack (asset names)
BenChaimberg Feb 26, 2020
8933a67
add integ test verification comment about glue cold start
BenChaimberg Feb 27, 2020
becef82
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 27, 2020
7db0ab0
cleaned up the note around cold start
Feb 28, 2020
45bfbd5
Merge branch 'master' into glue_job_sfn_task
mergify[bot] Feb 28, 2020
f7b2147
specify glue job ARN in state machine role permissions
BenChaimberg Feb 28, 2020
f81ee8d
change state machine role permissions based on service integration pa…
BenChaimberg Feb 28, 2020
3cb54e3
Merge branch 'master' into glue_job_sfn_task
BenChaimberg Feb 28, 2020
2b41dbc
Merge branch 'glue_job_sfn_task' of github.com:BenChaimberg/aws-cdk i…
BenChaimberg Feb 28, 2020
6960a54
Merge branch 'master' into glue_job_sfn_task
mergify[bot] Mar 2, 2020
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
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './emr-add-step';
export * from './emr-cancel-step';
export * from './emr-modify-instance-fleet-by-name';
export * from './emr-modify-instance-group-by-name';
export * from './run-glue-job-task';
120 changes: 120 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/lib/run-glue-job-task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import * as iam from '@aws-cdk/aws-iam';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import { Duration, Stack } from '@aws-cdk/core';
import { getResourceArn } from './resource-arn-suffix';

/**
* Properties for RunGlueJobTask
*/
export interface RunGlueJobTaskProps {

/**
* The service integration pattern indicates different ways to start the Glue job.
*
* The valid value for Glue is either FIRE_AND_FORGET or SYNC.
*
* @default FIRE_AND_FORGET
*/
readonly integrationPattern?: sfn.ServiceIntegrationPattern;

/**
* The job arguments specifically for this run.
*
* For this job run, they replace the default arguments set in the job definition itself.
*
* @default - Default arguments set in the job definition
*/
readonly arguments?: { [key: string]: string };

/**
* The job run timeout.
*
* This is the maximum time that a job run can consume resources before it is terminated and enters TIMEOUT status.
* Must be at least 1 minute.
*
* @default - Default timeout set in the job definition
*/
readonly timeout?: Duration;

/**
* The name of the SecurityConfiguration structure to be used with this job run.
*
BenChaimberg marked this conversation as resolved.
Show resolved Hide resolved
* This must match the Glue API
* [single-line string pattern](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-common.html#aws-glue-api-regex-oneLine).
*
* @default - Default configuration set in the job definition
*/
readonly securityConfiguration?: string;

/**
* After a job run starts, the number of minutes to wait before sending a job run delay notification.
*
* Must be at least 1 minute.
*
* @default - Default delay set in the job definition
*/
readonly notifyDelayAfter?: Duration;
}

/**
* Invoke a Glue job as a Task
*
* OUTPUT: the output of this task is a JobRun structure, for details consult
* https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-runs.html#aws-glue-api-jobs-runs-JobRun
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-glue.html
*/
export class RunGlueJobTask implements sfn.IStepFunctionsTask {
private readonly integrationPattern: sfn.ServiceIntegrationPattern;

constructor(private readonly glueJobName: string, private readonly props: RunGlueJobTaskProps = {}) {
nija-at marked this conversation as resolved.
Show resolved Hide resolved
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;

const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.SYNC
];

if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call Glue.`);
}
}

public bind(task: sfn.Task): sfn.StepFunctionsTaskConfig {
const notificationProperty = this.props.notifyDelayAfter ? { NotifyDelayAfter: this.props.notifyDelayAfter.toMinutes() } : null;
let iamActions: string[] | undefined;
if (this.integrationPattern === sfn.ServiceIntegrationPattern.FIRE_AND_FORGET) {
iamActions = ["glue:StartJobRun"];
} else if (this.integrationPattern === sfn.ServiceIntegrationPattern.SYNC) {
iamActions = [
"glue:StartJobRun",
"glue:GetJobRun",
"glue:GetJobRuns",
"glue:BatchStopJobRun"
];
}
return {
resourceArn: getResourceArn("glue", "startJobRun", this.integrationPattern),
policyStatements: [new iam.PolicyStatement({
resources: [
Stack.of(task).formatArn({
service: "glue",
resource: "job",
resourceName: this.glueJobName
})
],
actions: iamActions
})],
metricPrefixSingular: 'GlueJob',
metricPrefixPlural: 'GlueJobs',
metricDimensions: { GlueJobName: this.glueJobName },
parameters: {
JobName: this.glueJobName,
Arguments: this.props.arguments,
Timeout: this.props.timeout?.toMinutes(),
SecurityConfiguration: this.props.securityConfiguration,
NotificationProperty: notificationProperty
}
};
}
}
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-s3-assets": "0.0.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"jest": "^24.9.0",
Expand All @@ -92,6 +93,7 @@
"@aws-cdk/aws-ecr": "0.0.0",
"@aws-cdk/aws-ecr-assets": "0.0.0",
"@aws-cdk/aws-ecs": "0.0.0",
"@aws-cdk/aws-glue": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/aws-kms": "0.0.0",
"@aws-cdk/aws-lambda": "0.0.0",
Expand All @@ -109,6 +111,7 @@
"@aws-cdk/aws-ecr": "0.0.0",
"@aws-cdk/aws-ecr-assets": "0.0.0",
"@aws-cdk/aws-ecs": "0.0.0",
"@aws-cdk/aws-glue": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/aws-kms": "0.0.0",
"@aws-cdk/aws-lambda": "0.0.0",
Expand Down
Loading