Skip to content

Commit

Permalink
fix(glue): added RayExecutableProps which supports s3PythonModules
Browse files Browse the repository at this point in the history
  • Loading branch information
moomindani committed Jan 9, 2024
1 parent 3656a4c commit cde94af
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 317 deletions.
32 changes: 30 additions & 2 deletions packages/@aws-cdk/aws-glue-alpha/lib/job-executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ interface PythonExecutableProps {
readonly extraPythonFiles?: Code[];
}

interface RayExecutableProps {
/**
* The Python version to use.
*/
readonly pythonVersion: PythonVersion;

/**
* Additional Python modules that AWS Glue adds to the Python path before executing your script.
*
* @default - no extra python files and argument is not set
*
* @see `--s3-py-modules` in https://docs.aws.amazon.com/glue/latest/dg/author-job-ray-job-parameters.html
*/
readonly s3PythonModules?: Code[];
}

interface SharedJobExecutableProps {
/**
* Runtime. It is required for Ray jobs.
Expand Down Expand Up @@ -253,7 +269,7 @@ export interface PythonShellExecutableProps extends SharedJobExecutableProps, Py
/**
* Props for creating a Python Ray job executable
*/
export interface PythonRayExecutableProps extends SharedJobExecutableProps, PythonExecutableProps {}
export interface PythonRayExecutableProps extends SharedJobExecutableProps, RayExecutableProps {}

/**
* The executable properties related to the Glue job's GlueVersion, JobType and code
Expand Down Expand Up @@ -377,14 +393,17 @@ export class JobExecutable {
if (JobLanguage.PYTHON !== config.language && config.extraPythonFiles) {
throw new Error('extraPythonFiles is not supported for languages other than JobLanguage.PYTHON');
}
if (config.extraPythonFiles && type === JobType.RAY.name) {
throw new Error('extraPythonFiles is not supported for Ray jobs');
}
if (config.pythonVersion === PythonVersion.THREE_NINE && type !== JobType.PYTHON_SHELL.name && type !== JobType.RAY.name) {
throw new Error('Specified PythonVersion PythonVersion.THREE_NINE is only supported for JobType Python Shell and Ray');
}
if (config.pythonVersion === PythonVersion.THREE && type === JobType.RAY.name) {
throw new Error('Specified PythonVersion PythonVersion.THREE is not supported for Ray');
}
if (config.runtime === undefined && type === JobType.RAY.name) {
throw new Error('Runtime is required for Ray jobs.');
throw new Error('Runtime is required for Ray jobs');
}
this.config = config;
}
Expand Down Expand Up @@ -466,6 +485,15 @@ export interface JobExecutableConfig {
*/
readonly extraPythonFiles?: Code[];

/**
* Additional Python modules that AWS Glue adds to the Python path before executing your script.
*
* @default - no extra python files specified.
*
* @see `--s3-py-modules` in https://docs.aws.amazon.com/glue/latest/dg/author-job-ray-job-parameters.html
*/
readonly s3PythonModules?: Code[];

/**
* Additional files, such as configuration files that AWS Glue copies to the working directory of your script before executing it.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-glue-alpha/lib/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,9 @@ export class Job extends JobBase {
if (config.extraPythonFiles && config.extraPythonFiles.length > 0) {
args['--extra-py-files'] = config.extraPythonFiles.map(code => this.codeS3ObjectUrl(code)).join(',');
}
if (config.s3PythonModules && config.s3PythonModules.length > 0) {
args['--s3-py-modules'] = config.s3PythonModules.map(code => this.codeS3ObjectUrl(code)).join(',');
}
if (config.extraFiles && config.extraFiles.length > 0) {
args['--extra-files'] = config.extraFiles.map(code => this.codeS3ObjectUrl(code)).join(',');
}
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cde94af

Please sign in to comment.