Created
October 4, 2023 12:09
Revisions
-
gjohnson created this gist
Oct 4, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import * as cdk from 'aws-cdk-lib'; import * as glue from 'aws-cdk-lib/aws-glue'; import * as redshift from 'aws-cdk-lib/aws-redshift'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as core from 'aws-cdk-lib/core'; export class YourCdkStack extends core.Stack { constructor(scope: core.Construct, id: string, props?: core.StackProps) { super(scope, id, props); // Create an S3 bucket for your JSON files const dataBucket = new s3.Bucket(this, 'DataBucket', { removalPolicy: core.RemovalPolicy.DESTROY, // Only for dev/test purposes }); // Create a Redshift cluster const redshiftCluster = new redshift.Cluster(this, 'RedshiftCluster', { masterUser: { masterUsername: 'your-master-username', masterPassword: cdk.SecretValue.plainText('your-master-password'), }, clusterType: redshift.ClusterType.SINGLE_NODE, // You can configure this as needed defaultDatabaseName: 'your-database-name', removalPolicy: core.RemovalPolicy.DESTROY, // Only for dev/test purposes }); // Create a Glue job const glueJob = new glue.CfnJob(this, 'GlueJob', { name: 'YourGlueJob', role: new iam.Role(this, 'GlueJobRole', { assumedBy: new iam.ServicePrincipal('glue.amazonaws.com'), }).roleArn, command: { name: 'glueetl', scriptLocation: `s3://${dataBucket.bucketName}/your-glue-job-script.py`, // Provide the path to your Glue job script }, defaultArguments: { '--job-language': 'python', '--job-bookmark-option': 'job-bookmark-enable', '--TempDir': `s3://${dataBucket.bucketName}/temp/`, // S3 temporary directory for Glue '--enable-continuous-cloudwatch-log': 'true', }, connections: { connections: ['your-connection-name'], // If you have a connection to Redshift }, maxRetries: 0, // You can configure this as needed timeout: 2880, // You can configure this as needed }); // Grant Glue job permissions to access S3 and Redshift dataBucket.grantReadWrite(glueJob); redshiftCluster.grantReadWrite(glueJob); // Add any other necessary configurations, triggers, or dependencies // ... // Output the Redshift cluster endpoint new core.CfnOutput(this, 'RedshiftClusterEndpoint', { value: redshiftCluster.clusterEndpoint.hostname, }); } } const app = new cdk.App(); new YourCdkStack(app, 'YourCdkStack');