PythonShellJob L2 construct
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.
Example
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 });
import aws_cdk as cdk
import aws_cdk.aws_iam as iam
# stack: cdk.Stack
# role: iam.IRole
# script: glue.Code
glue.PythonShellJob(stack, "ImportedJob", role=role, script=script)
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.iam.*;
Stack stack;
IRole role;
Code script;
PythonShellJob.Builder.create(stack, "ImportedJob").role(role).script(script).build();
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
using Amazon.CDK.AWS.IAM;
Stack stack;
IRole role;
Code script;
new PythonShellJob(stack, "ImportedJob", new PythonShellJobProps { Role = role, Script = script });
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import cdk "github.com/aws/aws-cdk-go/awscdk"
import iam "github.com/aws/aws-cdk-go/awscdk"
var stack Stack
var role IRole
var script Code
glue.NewPythonShellJob(stack, jsii.String("ImportedJob"), &PythonShellJobProps{
Role: Role,
Script: Script,
})
Initializer
new PythonShellJob(scope: Construct, id: string, props: PythonShellJobProps)
PythonShellJob(scope: Construct, id: str, props: PythonShellJobProps)
new PythonShellJob(Construct scope, String id, PythonShellJobProps props)
new PythonShellJob(Construct scope, string id, PythonShellJobProps props)
NewPythonShellJob(Scope Construct, Id *string, Props PythonShellJobProps)
Construct Props
connectionsIConnection[]connectionstyping.List[IConnection]connectionsList<IConnection>ConnectionsIConnection[]Connections*[]IConnection= [] - no connections are added to…#default
Default: [] - no connections are added to the job
continuousLoggingContinuousLoggingPropscontinuous_loggingContinuousLoggingPropscontinuousLoggingContinuousLoggingPropsContinuousLoggingContinuousLoggingPropsContinuousLoggingContinuousLoggingProps= continuous logging is enabled.#defaultArguments{ [key: string]: string }default_argumentstyping.Mapping[str, str]defaultArgumentsMap<String, String>DefaultArgumentsIDictionary<string, string>DefaultArguments*map[string]*string= no arguments#notes
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.
extraPythonFilesCode[]extra_python_filestyping.List[Code]extraPythonFilesList<Code>ExtraPythonFilesCode[]ExtraPythonFiles*[]Code= no extra Python files#Only individual files are supported, directories are not supported. Equivalent to the --extra-py-files job argument.
glueVersionGlueVersionglue_versionGlueVersionglueVersionGlueVersionGlueVersionGlueVersionGlueVersionGlueVersion= determined by the job type: 4.0 …#default
Default: determined by the job type: 4.0 for ETL and Streaming, 5.0 for Flex, 3.0 for Python Shell
jobNamestringjob_namestrjobNameStringJobNamestringJobName*string= a name is automatically generate…#default
Default: a name is automatically generated
jobRunQueuingEnabledbooleanjob_run_queuing_enabledbooljobRunQueuingEnabledBooleanJobRunQueuingEnabledboolJobRunQueuingEnabled*bool= false#notes
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.
librarySetLibrarySetlibrary_setLibrarySetlibrarySetLibrarySetLibrarySetLibrarySetLibrarySetLibrarySet= LibrarySet.ANALYTICS when runnin…#Only applies to jobs running Python 3.9. Set to LibrarySet.NONE when your libraries are custom or conflict with the pre-installed ones.
default
Default: LibrarySet.ANALYTICS when running Python 3.9, otherwise no library set is configured
maxCapacityMaxCapacitymax_capacityMaxCapacitymaxCapacityMaxCapacityMaxCapacityMaxCapacityMaxCapacityMaxCapacity= 0.0625#maxConcurrentRunsnumbermax_concurrent_runsint | floatmaxConcurrentRunsNumberMaxConcurrentRunsdoubleMaxConcurrentRuns*float64= 1#An error is returned when this threshold is reached. The maximum value you can specify is controlled by a service limit.
pythonVersionPythonVersionpython_versionPythonVersionpythonVersionPythonVersionPythonVersionPythonVersionPythonVersionPythonVersion= PythonVersion.THREE_NINE#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.
Can be uploaded from the local directory structure using fromAsset or referenced via S3 location using fromBucket
securityConfigurationISecurityConfigurationsecurity_configurationISecurityConfigurationsecurityConfigurationISecurityConfigurationSecurityConfigurationISecurityConfigurationSecurityConfigurationISecurityConfiguration= no security configuration.#tags{ [key: string]: string }tagstyping.Mapping[str, str]tagsMap<String, String>TagsIDictionary<string, string>Tags*map[string]*string= {} - no tags#timeoutDurationtimeoutDurationtimeoutDurationTimeoutDurationTimeoutDuration= no value set; Glue applies its s…#Specified in minutes.
default
Default: no value set; Glue applies its service default (2880 minutes for non-streaming jobs)
Properties
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
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.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#jobRefJobReferencejob_refJobReferencejobRefJobReferenceJobRefJobReferenceJobRefJobReferencerequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#Methods
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
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
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
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@staticmethod def from_job_attributes(scope: Construct, id: str, attrs: JobAttributes) -> IJobpublic static IJob fromJobAttributes(Construct scope, String id, JobAttributes attrs)public static IJob FromJobAttributes(Construct scope, string id, JobAttributes attrs)func FromJobAttributes(Scope Construct, Id *string, Attrs JobAttributes) IJobstatic#3 parameters
Parameters
scopescopescopescopeScope— The scope creating construct (usuallythis).ididididId— The construct's id.attrsattrsattrsattrsAttrs— Attributes for the Glue Job we want to import.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
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
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#metric(metricName: string, type: MetricType, props?: MetricOptions): Metricdef metric(self, metric_name: str, type: MetricType, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricType type, MetricOptions props)public Metric Metric(string metricName, MetricType type, MetricOptions? props = null)func Metric(MetricName *string, Type MetricType, Props MetricOptions) Metric#3 parameters
Parameters
metricNamemetric_namemetricNamemetricNameMetricName— name of the metric typically prefixed withglue.driver.,glue.<executorId>.orglue.ALL..typetypetypetypeType— the metric type.propspropspropspropsProps— metric options.
metricFailure(props?: MetricOptions): Metricdef metric_failure(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricFailure(MetricOptions props)public Metric MetricFailure(MetricOptions? props = null)func MetricFailure(Props MetricOptions) Metric#This metric is based on the Rule returned by no-args onFailure() call.
metricSuccess(props?: MetricOptions): Metricdef metric_success(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricSuccess(MetricOptions props)public Metric MetricSuccess(MetricOptions? props = null)func MetricSuccess(Props MetricOptions) Metric#This metric is based on the Rule returned by no-args onSuccess() call.
metricTimeout(props?: MetricOptions): Metricdef metric_timeout(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricTimeout(MetricOptions props)public Metric MetricTimeout(MetricOptions? props = null)func MetricTimeout(Props MetricOptions) Metric#This metric is based on the Rule returned by no-args onTimeout() call.
onEvent(id: string, options?: OnEventOptions): Ruledef on_event(self, id: str, options: typing.Optional[OnEventOptions] = None) -> Rulepublic Rule onEvent(String id, OnEventOptions options)public Rule OnEvent(string id, OnEventOptions? options = null)func OnEvent(Id *string, Options OnEventOptions) Rule#2 parameters
Parameters
ididididId— construct id.optionsoptionsoptionsoptionsOptions— event options.
onFailure(id: string, options?: OnEventOptions): Ruledef on_failure(self, id: str, options: typing.Optional[OnEventOptions] = None) -> Rulepublic Rule onFailure(String id, OnEventOptions options)public Rule OnFailure(string id, OnEventOptions? options = null)func OnFailure(Id *string, Options OnEventOptions) Rule#2 parameters
Parameters
ididididId— construct id.optionsoptionsoptionsoptionsOptions— optional event options.
onSuccess(id: string, options?: OnEventOptions): Ruledef on_success(self, id: str, options: typing.Optional[OnEventOptions] = None) -> Rulepublic Rule onSuccess(String id, OnEventOptions options)public Rule OnSuccess(string id, OnEventOptions? options = null)func OnSuccess(Id *string, Options OnEventOptions) Rule#2 parameters
Parameters
ididididId— construct id.optionsoptionsoptionsoptionsOptions— optional event options.
onTimeout(id: string, options?: OnEventOptions): Ruledef on_timeout(self, id: str, options: typing.Optional[OnEventOptions] = None) -> Rulepublic Rule onTimeout(String id, OnEventOptions options)public Rule OnTimeout(string id, OnEventOptions? options = null)func OnTimeout(Id *string, Options OnEventOptions) Rule#2 parameters
Parameters
ididididId— construct id.optionsoptionsoptionsoptionsOptions— optional event options.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#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.