# PythonShellJob

Python Shell Jobs class.

A Python shell job runs Python scripts as a shell and supports a Python version that
depends on the AWS Glue version you are using.
This can be used to schedule and run tasks that don't require an Apache Spark environment.

Extends: Construct › Resource › JobBase › Job › PythonShellJob
Implements: IJob, IResource, IGrantable, IEnvironmentAware, IJobRef, IConstruct, IDependable

- Source: [`lib/jobs/python-shell-job.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-glue-alpha/lib/jobs/python-shell-job.ts#L78)
- Type last changed: v2.270.0-alpha.0 · 18 Sep 2026

## Example

```ts
import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const stack: cdk.Stack;
declare const role: iam.IRole;
declare const script: glue.Code;
new glue.PythonShellJob(stack, 'ImportedJob', { role, script });
```

## Initializer

```ts
new PythonShellJob(scope: Construct, id: string, props: PythonShellJobProps)
```

## Construct Props

- `connections`: [IConnection](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.IConnection.html)[] — Connections (optional) List of connections to use for this Glue job Connections are used to connect to other AWS Service or resources within a VPC.

  **Default:** [] - no connections are added to the job

- `continuousLogging`: [ContinuousLoggingProps](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.ContinuousLoggingProps.html) — Enables continuous logging with the specified props.

  **Default:** continuous logging is enabled.

- `defaultArguments`: { [key: string]: string } — Default Arguments (optional) The default arguments for every run of this Glue job, specified as name-value pairs.

  **Default:** no arguments

  This map is the escape hatch for Glue job arguments that this construct does not model. It
  MUST NOT be used to set arguments that already have a dedicated prop — configure those through
  the corresponding prop instead (`continuousLogging`, `enableMetrics`,
  `enableObservabilityMetrics`, `sparkUI`, `className`, `extraJars`, `extraJarsFirst`,
  `extraPythonFiles`, `extraFiles`). Passing a construct-managed argument (e.g.
  `--enable-continuous-cloudwatch-log`, `--enable-metrics`, `--enable-spark-ui`,
  `--job-language`) or a Glue-reserved argument (`--debug`, `--mode`, `--JOB_NAME`, `--endpoint`)
  here throws at synthesis time, so there is exactly one way to express each intent.

  Also note that these are emitted verbatim into the CloudFormation template, so avoid
  placing secrets here in plaintext. Pass secrets to the job at runtime
  through AWS Secrets Manager instead. A synthesis-time warning is emitted
  when an argument key looks like a credential and holds a plaintext literal.

- `description`: string — Description (optional) Developer-specified description of the Glue job.

  **Default:** no value

- `extraPythonFiles`: [Code](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.Code.html)[] — Additional Python files that AWS Glue adds to the Python path before executing your script.

  **Default:** no extra Python files

  Only individual files are supported, directories are not supported.
  Equivalent to the `--extra-py-files` job argument.

- `glueVersion`: [GlueVersion](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.GlueVersion.html) — Glue Version The version of Glue to use to execute this job.

  **Default:** determined by the job type: 4.0 for ETL and Streaming, 5.0 for Flex, 3.0 for Python Shell

- `jobName`: string — Name of the Glue job (optional) Developer-specified name of the Glue job.

  **Default:** a name is automatically generated

- `jobRunQueuingEnabled`: boolean = false — Specifies whether job run queuing is enabled for the job runs for this job.

  A value of true means job run queuing is enabled for the job runs.
  If false or not populated, the job runs will not be considered for queueing.
  If this field does not match the value set in the job run, then the value from
  the job run field will be used. This property must be set to false for flex jobs.
  If this property is enabled, maxRetries must be set to zero.

- `librarySet`: [LibrarySet](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.LibrarySet.html) — The set of pre-installed Python libraries to make available to the job.

  **Default:** LibrarySet.ANALYTICS when running Python 3.9, otherwise no library set is configured

  Only applies to jobs running Python 3.9. Set to `LibrarySet.NONE` when your libraries are
  custom or conflict with the pre-installed ones.

- `maxCapacity`: [MaxCapacity](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.MaxCapacity.html) = 0.0625 — The total number of DPU to assign to the Python Job.

- `maxConcurrentRuns`: number = 1 — Max Concurrent Runs (optional) The maximum number of runs this Glue job can concurrently run.

  An error is returned when this threshold is reached. The maximum value
  you can specify is controlled by a service limit.

- `maxRetries`: number = 0 — Max Retries (optional) Maximum number of retry attempts Glue performs if the job fails.

- `pythonVersion`: [PythonVersion](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.PythonVersion.html) = PythonVersion.THREE_NINE — The version of Python to use to execute this job.

  Python shell jobs only support `PythonVersion.THREE_NINE`. The older `PythonVersion.TWO`
  (Python 2.7) and `PythonVersion.THREE` (Python 3.6) runtimes have been retired by AWS Glue
  and are no longer available for Python shell jobs.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) (required) — IAM Role (required) IAM Role to use for Glue job execution Must be specified by the developer because the L2 doesn't have visibility into the actions the script(s) takes during the job execution The role must trust the Glue service principal (glue.amazonaws.com) and be granted sufficient permissions.

- `script`: [Code](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.Code.html) (required) — Script Code Location (required) Script to run when the Glue job executes.

  Can be uploaded
  from the local directory structure using fromAsset
  or referenced via S3 location using fromBucket

- `securityConfiguration`: [ISecurityConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-glue-alpha.ISecurityConfiguration.html) — Security Configuration (optional) Defines the encryption options for the Glue job.

  **Default:** no security configuration.

- `tags`: { [key: string]: string } — Tags (optional) A list of key:value pairs of tags to apply to this Glue job resources.

  **Default:** {} - no tags

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Timeout (optional) The maximum time that a job run can consume resources before it is terminated and enters TIMEOUT status.

  **Default:** 2880 (2 days for non-streaming)

  Specified in minutes.

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) (required) — The principal to grant permissions to.

- `jobArn`: string (required) — The ARN of the job.

- `jobName`: string (required) — The name of the job.

- `jobRef`: [JobReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_glue.JobReference.html) (required) — A reference to this Job resource, for use with the generated L1 ref interface.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) (required) — The IAM role Glue assumes to run this job.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromJobAttributes(scope: Construct, id: string, attrs: JobAttributes): IJob` (static) — Identifies an existing Glue Job from a subset of attributes that can be referenced from within another Stack or Construct.

  **Parameters**

  - `scope` — The scope creating construct (usually `this`).
  - `id` — The construct's id.
  - `attrs` — Attributes for the Glue Job we want to import.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `metric(metricName: string, type: MetricType, props?: MetricOptions): Metric` — Create a CloudWatch metric.

  **Parameters**

  - `metricName` — name of the metric typically prefixed with `glue.driver.`, `glue.<executorId>.` or `glue.ALL.`.
  - `type` — the metric type.
  - `props` — metric options.

- `metricFailure(props?: MetricOptions): Metric` — Return a CloudWatch Metric indicating job failure.

  This metric is based on the Rule returned by no-args onFailure() call.

- `metricSuccess(props?: MetricOptions): Metric` — Return a CloudWatch Metric indicating job success.

  This metric is based on the Rule returned by no-args onSuccess() call.

- `metricTimeout(props?: MetricOptions): Metric` — Return a CloudWatch Metric indicating job timeout.

  This metric is based on the Rule returned by no-args onTimeout() call.

- `onEvent(id: string, options?: OnEventOptions): Rule` — Create a CloudWatch Event Rule for this Glue Job when it's in a given state.

  **Parameters**

  - `id` — construct id.
  - `options` — event options.

- `onFailure(id: string, options?: OnEventOptions): Rule` — Return a CloudWatch Event Rule matching FAILED state.

  **Parameters**

  - `id` — construct id.
  - `options` — optional event options.

- `onSuccess(id: string, options?: OnEventOptions): Rule` — Create a CloudWatch Event Rule matching JobState.SUCCEEDED.

  **Parameters**

  - `id` — construct id.
  - `options` — optional event options.

- `onTimeout(id: string, options?: OnEventOptions): Rule` — Return a CloudWatch Event Rule matching TIMEOUT state.

  **Parameters**

  - `id` — construct id.
  - `options` — optional event options.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
