Skip to content
v2.275.0

Workflow L2 construct ​

This module defines a construct for creating and managing AWS Glue Workflows and Triggers.

AWS Glue Workflows are orchestration services that allow you to create, manage, and monitor complex extract, transform, and load (ETL) activities involving multiple crawlers, jobs, and triggers. Workflows are designed to allow you to manage interdependent jobs and crawlers as a single unit, making it easier to orchestrate and monitor complex ETL pipelines.

Triggers are used to initiate an AWS Glue Workflow. You can configure different types of triggers, such as on-demand, scheduled, event-based, or conditional triggers, to start your Workflow based on specific conditions or events.

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;

// Create a job to run from the workflow
const job = new glue.PySparkEtlJob(stack, 'Job', { role, script });

// Create a workflow and add a trigger that runs the job
const workflow = new glue.Workflow(stack, 'Workflow');
workflow.addOnDemandTrigger('OnDemandTrigger', {
  actions: [glue.Action.job(job)],
});
python
import aws_cdk as cdk
import aws_cdk.aws_iam as iam
# stack: cdk.Stack
# role: iam.IRole
# script: glue.Code


# Create a job to run from the workflow
job = glue.PySparkEtlJob(stack, "Job", role=role, script=script)

# Create a workflow and add a trigger that runs the job
workflow = glue.Workflow(stack, "Workflow")
workflow.add_on_demand_trigger("OnDemandTrigger",
    actions=[glue.Action.job(job)]
)
java
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.iam.*;
Stack stack;
IRole role;
Code script;


// Create a job to run from the workflow
PySparkEtlJob job = PySparkEtlJob.Builder.create(stack, "Job").role(role).script(script).build();

// Create a workflow and add a trigger that runs the job
Workflow workflow = new Workflow(stack, "Workflow");
workflow.addOnDemandTrigger("OnDemandTrigger", OnDemandTriggerOptions.builder()
        .actions(List.of(Action.job(job)))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
using Amazon.CDK.AWS.IAM;
Stack stack;
IRole role;
Code script;


// Create a job to run from the workflow
var job = new PySparkEtlJob(stack, "Job", new PySparkEtlJobProps { Role = role, Script = script });

// Create a workflow and add a trigger that runs the job
var workflow = new Workflow(stack, "Workflow");
workflow.AddOnDemandTrigger("OnDemandTrigger", new OnDemandTriggerOptions {
    Actions = new [] { Action.Job(job) }
});
go
// 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


// Create a job to run from the workflow
job := glue.NewPySparkEtlJob(stack, jsii.String("Job"), &PySparkEtlJobProps{
	Role: Role,
	Script: Script,
})

// Create a workflow and add a trigger that runs the job
workflow := glue.NewWorkflow(stack, jsii.String("Workflow"))
workflow.AddOnDemandTrigger(jsii.String("OnDemandTrigger"), &OnDemandTriggerOptions{
	Actions: []Action{
		glue.Action_Job(job),
	},
})

Initializer ​

ts
new Workflow(scope: Construct, id: string, props?: WorkflowProps)
python
Workflow(scope: Construct, id: str, props: typing.Optional[WorkflowProps] = None)
java
new Workflow(Construct scope, String id, WorkflowProps props)
csharp
new Workflow(Construct scope, string id, WorkflowProps? props = null)
go
NewWorkflow(Scope Construct, Id *string, Props WorkflowProps)

Construct Props ​

defaultRunPropertiesoptional{ [key: string]: string }default_run_propertiesoptionaltyping.Mapping[str, str]defaultRunPropertiesoptionalMap<String, String>DefaultRunPropertiesoptionalIDictionary<string, string>DefaultRunPropertiesoptional*map[string]*string#
A map of properties to use when this workflow is executed.

Default: no default run properties

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string#
A description of the workflow.

Default: no description

maxConcurrentRunsoptionalnumbermax_concurrent_runsoptionalint | floatmaxConcurrentRunsoptionalNumberMaxConcurrentRunsoptionaldoubleMaxConcurrentRunsoptional*float64#
The maximum number of concurrent runs allowed for the workflow.

Default: no limit

workflowNameoptionalstringworkflow_nameoptionalstrworkflowNameoptionalStringWorkflowNameoptionalstringWorkflowNameoptional*string#
Name of the workflow.

Default: a name will be generated

Properties ​

The environment this resource belongs to.
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.

nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.
workflowArnstringworkflow_arnstrworkflowArnStringWorkflowArnstringWorkflowArn*string#
The ARN of the workflow.
workflowNamestringworkflow_namestrworkflowNameStringWorkflowNamestringWorkflowName*string#
The name of the workflow.

Methods ​

addConditionalTrigger(id: string, options: ConditionalTriggerOptions): ITriggerRefdef add_conditional_trigger(self, id: str, options: ConditionalTriggerOptions) -> ITriggerRefpublic ITriggerRef addConditionalTrigger(String id, ConditionalTriggerOptions options)public ITriggerRef AddConditionalTrigger(string id, ConditionalTriggerOptions options)func AddConditionalTrigger(Id *string, Options ConditionalTriggerOptions) ITriggerRef#
Add a conditional (predicate-based) trigger to the workflow.
2 parameters · returns

Parameters

  • ididididId — The id of the trigger.
  • optionsoptionsoptionsoptionsOptions — Additional options for the trigger.

Returns: a reference to the created trigger.

addEventTrigger(id: string, options: EventTriggerOptions): ITriggerRefdef add_event_trigger(self, id: str, options: EventTriggerOptions) -> ITriggerRefpublic ITriggerRef addEventTrigger(String id, EventTriggerOptions options)public ITriggerRef AddEventTrigger(string id, EventTriggerOptions options)func AddEventTrigger(Id *string, Options EventTriggerOptions) ITriggerRef#
Add an EventBridge event-based trigger to the workflow.
2 parameters · returns

Parameters

  • ididididId — The id of the trigger.
  • optionsoptionsoptionsoptionsOptions — Additional options for the trigger.

Returns: a reference to the created trigger.

addOnDemandTrigger(id: string, options: OnDemandTriggerOptions): ITriggerRefdef add_on_demand_trigger(self, id: str, options: OnDemandTriggerOptions) -> ITriggerRefpublic ITriggerRef addOnDemandTrigger(String id, OnDemandTriggerOptions options)public ITriggerRef AddOnDemandTrigger(string id, OnDemandTriggerOptions options)func AddOnDemandTrigger(Id *string, Options OnDemandTriggerOptions) ITriggerRef#
Add an on-demand trigger to the workflow.
2 parameters · returns

Parameters

  • ididididId — The id of the trigger.
  • optionsoptionsoptionsoptionsOptions — Additional options for the trigger.

Returns: a reference to the created trigger.

addScheduledTrigger(id: string, options: ScheduledTriggerOptions): ITriggerRefdef add_scheduled_trigger(self, id: str, options: ScheduledTriggerOptions) -> ITriggerRefpublic ITriggerRef addScheduledTrigger(String id, ScheduledTriggerOptions options)public ITriggerRef AddScheduledTrigger(string id, ScheduledTriggerOptions options)func AddScheduledTrigger(Id *string, Options ScheduledTriggerOptions) ITriggerRef#
Add a scheduled trigger to the workflow.
2 parameters · returns

Parameters

  • ididididId — The id of the trigger.
  • optionsoptionsoptionsoptionsOptions — Additional options for the trigger, including the schedule.

Returns: a reference to the created trigger.

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)#
Override the cross-stack reference strength for this resource.
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)#
Apply the given removal policy to this resource.
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).

fromWorkflowArn(scope: Construct, id: string, workflowArn: string): IWorkflow@staticmethod def from_workflow_arn(scope: Construct, id: str, workflow_arn: str) -> IWorkflowpublic static IWorkflow fromWorkflowArn(Construct scope, String id, String workflowArn)public static IWorkflow FromWorkflowArn(Construct scope, string id, string workflowArn)func FromWorkflowArn(Scope Construct, Id *string, WorkflowArn *string) IWorkflowstatic#
Import a workflow from its name.
fromWorkflowAttributes(scope: Construct, id: string, attrs: WorkflowAttributes): IWorkflow@staticmethod def from_workflow_attributes(scope: Construct, id: str, attrs: WorkflowAttributes) -> IWorkflowpublic static IWorkflow fromWorkflowAttributes(Construct scope, String id, WorkflowAttributes attrs)public static IWorkflow FromWorkflowAttributes(Construct scope, string id, WorkflowAttributes attrs)func FromWorkflowAttributes(Scope Construct, Id *string, Attrs WorkflowAttributes) IWorkflowstatic#
Import an existing workflow.
fromWorkflowName(scope: Construct, id: string, workflowName: string): IWorkflow@staticmethod def from_workflow_name(scope: Construct, id: str, workflow_name: str) -> IWorkflowpublic static IWorkflow fromWorkflowName(Construct scope, String id, String workflowName)public static IWorkflow FromWorkflowName(Construct scope, string id, string workflowName)func FromWorkflowName(Scope Construct, Id *string, WorkflowName *string) IWorkflowstatic#
Import a workflow from its name.
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#
Checks if `x` is a construct.
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#
Returns true if the construct was created by CDK, and false otherwise.
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#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.