Skip to content

Instantly share code, notes, and snippets.

@gjohnson
Created October 4, 2023 12:15
Show Gist options
  • Save gjohnson/e1b34f64bbfc932a9006611d24624885 to your computer and use it in GitHub Desktop.
Save gjohnson/e1b34f64bbfc932a9006611d24624885 to your computer and use it in GitHub Desktop.
import * as cdk from 'aws-cdk-lib';
import * as glue from 'aws-cdk-lib/aws-glue';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
class GlueWorkflowStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create an S3 bucket for source data
const sourceBucket = new s3.Bucket(this, 'SourceBucket', {
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
// Create a Glue job
const glueJob = new glue.CfnJob(this, 'MyGlueJob', {
command: {
name: 'glueetl',
scriptLocation: `s3://${sourceBucket.bucketName}/path-to-your-glue-script.py`,
},
role: iam.Role.fromRoleArn(this, 'GlueJobRole', 'YOUR-GLUE-JOB-ROLE-ARN'),
});
// Define a Glue workflow
const glueWorkflow = new glue.CfnWorkflow(this, 'MyGlueWorkflow', {
defaultRunProperties: {
JobName: glueJob.ref,
},
});
// Add a trigger to the workflow (e.g., schedule)
const trigger = new glue.CfnTrigger(this, 'MyGlueTrigger', {
actions: [
{
jobName: glueJob.ref,
},
],
type: 'SCHEDULED',
schedule: 'cron(0 0 * * ? *)', // Runs daily at midnight
workflowName: glueWorkflow.ref,
});
}
}
const app = new cdk.App();
new GlueWorkflowStack(app, 'GlueWorkflowStack');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment