2.0.300 • Published 1 day ago

cdk-databrew-cicd v2.0.300

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 day ago

cdk-databrew-cicd

This construct creates a CodePipeline pipeline where users can push a DataBrew recipe into the CodeCommit repository and the recipe will be pushed to a pre-production AWS account and a production AWS account by order automatically.

npm (JS/TS)PyPI (Python)Maven (Java)GoNuGet
LinkLinkLinkLinkLink

License Release npm downloads pypi downloads NuGet downloads repo languages

Table of Contents

Serverless Architecture

image Romi B. and Gaurav W., 2021

Introduction

The architecture was introduced by Romi Boimer and Gaurav Wadhawan and was posted on the AWS Blog as Set up CI/CD pipelines for AWS Glue DataBrew using AWS Developer Tools.
I converted the architecture into a CDK construct for 4 programming languages. Before applying the AWS construct, make sure you've set up a proper IAM role for the pre-production and production AWS accounts. You could achieve it either by creating manually or creating through a custom construct in this library.

import { IamRole } from 'cdk-databrew-cicd';

new IamRole(this, 'AccountIamRole', {
    environment: 'preproduction', // or 'production'
    accountID: 'ACCOUNT_ID',
    // roleName: 'OPTIONAL'
});

Example

Typescript

You could also refer to here.

$ cdk --init language typescript
$ yarn add cdk-databrew-cicd
import * as cdk from '@aws-cdk/core';
import { DataBrewCodePipeline } from 'cdk-databrew-cicd';

class TypescriptStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const preproductionAccountId = 'PREPRODUCTION_ACCOUNT_ID';
    const productionAccountId = 'PRODUCTION_ACCOUNT_ID';

    const dataBrewPipeline = new DataBrewCodePipeline(this, 'DataBrewCicdPipeline', {
      preproductionIamRoleArn: `arn:${cdk.Aws.PARTITION}:iam::${preproductionAccountId}:role/preproduction-Databrew-Cicd-Role`,
      productionIamRoleArn: `arn:${cdk.Aws.PARTITION}:iam::${productionAccountId}:role/production-Databrew-Cicd-Role`,
      // bucketName: 'OPTIONAL',
      // repoName: 'OPTIONAL',
      // branchName: 'OPTIONAL',
      // pipelineName: 'OPTIONAL'
    });

    new cdk.CfnOutput(this, 'OPreproductionLambdaArn', { value: dataBrewPipeline.preproductionFunctionArn });
    new cdk.CfnOutput(this, 'OProductionLambdaArn', { value: dataBrewPipeline.productionFunctionArn });
    new cdk.CfnOutput(this, 'OCodeCommitRepoArn', { value: dataBrewPipeline.codeCommitRepoArn });
    new cdk.CfnOutput(this, 'OCodePipelineArn', { value: dataBrewPipeline.codePipelineArn });
  }
}

const app = new cdk.App();
new TypescriptStack(app, 'TypescriptStack', {
  stackName: 'DataBrew-CICD'
});

Python

You could also refer to here.

# upgrading related Python packages
$ python -m ensurepip --upgrade
$ python -m pip install --upgrade pip
$ python -m pip install --upgrade virtualenv
# initialize a CDK Python project
$ cdk init --language python
# make packages installed locally instead of globally
$ source .venv/bin/activate
$ cat <<EOL > requirements.txt
aws-cdk.core
cdk-databrew-cicd
EOL
$ python -m pip install -r requirements.txt
from aws_cdk import core as cdk
from cdk_databrew_cicd import DataBrewCodePipeline

class PythonStack(cdk.Stack):

    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        preproduction_account_id = "PREPRODUCTION_ACCOUNT_ID"
        production_account_id = "PRODUCTION_ACCOUNT_ID"

        databrew_pipeline = DataBrewCodePipeline(self,
        "DataBrewCicdPipeline",
        preproduction_iam_role_arn=f"arn:{cdk.Aws.PARTITION}:iam::{preproduction_account_id}:role/preproduction-Databrew-Cicd-Role",
        production_iam_role_arn=f"arn:{cdk.Aws.PARTITION}:iam::{production_account_id}:role/preproduction-Databrew-Cicd-Role",
            # bucket_name="OPTIONAL",
            # repo_name="OPTIONAL",
            # repo_name="OPTIONAL",
            # branch_namne="OPTIONAL",
            # pipeline_name="OPTIONAL"
            )

        cdk.CfnOutput(self, 'OPreproductionLambdaArn', value=databrew_pipeline.preproduction_function_arn)
        cdk.CfnOutput(self, 'OProductionLambdaArn', value=databrew_pipeline.production_function_arn)
        cdk.CfnOutput(self, 'OCodeCommitRepoArn', value=databrew_pipeline.code_commit_repo_arn)
        cdk.CfnOutput(self, 'OCodePipelineArn', value=databrew_pipeline.code_pipeline_arn)
$ deactivate

Java

You could also refer to here.

$ cdk init --language java
$ mvn package
.
.
<properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <cdk.version>2.87.0</cdk.version>
      <constrcut.verion>2.0.196</constrcut.verion>
      <junit.version>5.7.1</junit.version>
</properties>
 .
 .
 <dependencies>
     <!-- AWS Cloud Development Kit -->
      <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>aws-cdk-lib</artifactId>
            <version>${cdk.version}</version>
      </dependency>
      <dependency>
        <groupId>io.github.hsiehshujeng</groupId>
        <artifactId>cdk-databrew-cicd</artifactId>
        <version>${constrcut.verion}</version>
        </dependency>
     .
     .
     .
 </dependencies>
package com.myorg;

import software.amazon.awscdk.core.CfnOutput;
import software.amazon.awscdk.core.CfnOutputProps;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import io.github.hsiehshujeng.cdk.databrew.cicd.DataBrewCodePipeline;
import io.github.hsiehshujeng.cdk.databrew.cicd.DataBrewCodePipelineProps;

public class JavaStack extends Stack {
    public JavaStack(final Construct scope, final String id) {
        this(scope, id, null);
    }

    public JavaStack(final Construct scope, final String id, final StackProps props) {
        super(scope, id, props);
        String preproductionAccountId = "PREPRODUCTION_ACCOUNT_ID";
        String productionAccountId = "PRODUCTION_ACCOUNT_ID";
        DataBrewCodePipeline databrewPipeline = new DataBrewCodePipeline(this, "DataBrewCicdPipeline",
                DataBrewCodePipelineProps.builder().preproductionIamRoleArn(preproductionAccountId)
                        .productionIamRoleArn(productionAccountId)
                        // .bucketName("OPTIONAL")
                        // .branchName("OPTIONAL")
                        // .pipelineName("OPTIONAL")
                        .build());

        new CfnOutput(this, "OPreproductionLambdaArn",
                CfnOutputProps.builder()
                    .value(databrewPipeline.getPreproductionFunctionArn())
                    .build());
        new CfnOutput(this, "OProductionLambdaArn",
                CfnOutputProps.builder()
                    .value(databrewPipeline.getProductionFunctionArn())
                    .build());
        new CfnOutput(this, "OCodeCommitRepoArn",
                CfnOutputProps.builder()
                    .value(databrewPipeline.getCodeCommitRepoArn())
                    .build());
        new CfnOutput(this, "OCodePipelineArn",
                CfnOutputProps.builder()
                    .value(databrewPipeline.getCodePipelineArn())
                    .build());
    }
}

C

You could also refer to here.

$ cdk init --language csharp
$ dotnet add src/Csharp package Databrew.Cicd --version 2.0.196
using Amazon.CDK;
using ScottHsieh.Cdk;

namespace Csharp
{
    public class CsharpStack : Stack
    {
        internal CsharpStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            var preproductionAccountId = "PREPRODUCTION_ACCOUNT_ID";
            var productionAccountId = "PRODUCTION_ACCOUNT_ID";

            var dataBrewPipeline = new DataBrewCodePipeline(this, "DataBrewCicdPipeline", new DataBrewCodePipelineProps
            {
                PreproductionIamRoleArn = $"arn:{Aws.PARTITION}:iam::{preproductionAccountId}:role/preproduction-Databrew-Cicd-Role",
                ProductionIamRoleArn = $"arn:{Aws.PARTITION}:iam::{productionAccountId}:role/preproduction-Databrew-Cicd-Role",
                // BucketName = "OPTIONAL",
                // RepoName = "OPTIONAL",
                // BranchName = "OPTIONAL",
                // PipelineName = "OPTIONAL"
            });
            new CfnOutput(this, "OPreproductionLambdaArn", new CfnOutputProps
            {
                Value = dataBrewPipeline.PreproductionFunctionArn
            });
            new CfnOutput(this, "OProductionLambdaArn", new CfnOutputProps
            {
                Value = dataBrewPipeline.ProductionFunctionArn
            });
            new CfnOutput(this, "OCodeCommitRepoArn", new CfnOutputProps
            {
                Value = dataBrewPipeline.CodeCommitRepoArn
            });
            new CfnOutput(this, "OCodePipelineArn", new CfnOutputProps
            {
                Value = dataBrewPipeline.CodeCommitRepoArn
            });
        }
    }
}

Go

You could also refer to here.

# Initialize a new AWS CDK application in the current directory with the Go programming language
cdk init app -l go
# Add this custom CDK construct to your project
go get github.com/HsiehShuJeng/cdk-databrew-cicd-go/cdkdatabrewcicd/v2@v2.0.196
# Ensure all dependencies are properly listed in the go.mod file and remove any unused ones
go mod tidy
# Upgrade all Go modules in your project to their latest minor or patch versions
go get -u ./...
package main

import (
	"fmt"

	"github.com/aws/aws-cdk-go/awscdk/v2"

	// "github.com/aws/aws-cdk-go/awscdk/v2/awssqs"
	"github.com/HsiehShuJeng/cdk-databrew-cicd-go/cdkdatabrewcicd/v2"
	"github.com/aws/constructs-go/constructs/v10"
	"github.com/aws/jsii-runtime-go"
)

type GoLangStackProps struct {
	awscdk.StackProps
}

func NewGoLangStack(scope constructs.Construct, id string, props *GoLangStackProps) awscdk.Stack {
	var sprops awscdk.StackProps
	if props != nil {
		sprops = props.StackProps
	}
	stack := awscdk.NewStack(scope, &id, &sprops)

	preproductionAccountId := "PREPRODUCTION_ACCOUNT_ID"
	productionAccountId := "PRODUCTION_ACCOUNT_ID"

	dataBrewPipeline := cdkdatabrewcicd.NewDataBrewCodePipeline(stack, jsii.String("DataBrewCicdPipeline"), &cdkdatabrewcicd.DataBrewCodePipelineProps{
		PreproductionIamRoleArn: jsii.String(fmt.Sprintf("arn:%s:iam::%s:role/preproduction-Databrew-Cicd-Role", *awscdk.Aws_PARTITION(), preproductionAccountId)),
		ProductionIamRoleArn:    jsii.String(fmt.Sprintf("arn:%s:iam::%s:role/production-Databrew-Cicd-Role", *awscdk.Aws_PARTITION(), productionAccountId)),
		// BucketName:   jsii.String("OPTIONAL"),
		// RepoName:     jsii.String("OPTIONAL"),
		// BranchName:   jsii.String("OPTIONAL"),
		// PipelineName: jsii.String("OPTIONAL"),
	})

	awscdk.NewCfnOutput(stack, jsii.String("OPreproductionLambdaArn"), &awscdk.CfnOutputProps{Value: dataBrewPipeline.PreproductionFunctionArn()})
	awscdk.NewCfnOutput(stack, jsii.String("OProductionLambdaArn"), &awscdk.CfnOutputProps{Value: dataBrewPipeline.ProductionFunctionArn()})
	awscdk.NewCfnOutput(stack, jsii.String("OCodeCommitRepoArn"), &awscdk.CfnOutputProps{Value: dataBrewPipeline.CodeCommitRepoArn()})
	awscdk.NewCfnOutput(stack, jsii.String("OCodePipelineArn"), &awscdk.CfnOutputProps{Value: dataBrewPipeline.CodePipelineArn()})

	return stack
}

func main() {
	defer jsii.Close()

	app := awscdk.NewApp(nil)

	NewGoLangStack(app, "GoLangStack", &GoLangStackProps{
		awscdk.StackProps{
			Env: env(),
		},
	})

	app.Synth(nil)
}

func env() *awscdk.Environment {
	return nil
}

Some Efforts after Stack Creation

CodeCommit

  1. Create HTTPS Git credentials for AWS CodeCommit with an IAM user that you're going to use.
    image
  2. Run through the steps noted on the README.md of the CodeCommit repository after finishing establishing the stack via CDK. The returned message with success should be looked like the following (assume you have installed git-remote-codecommit):
    $ git clone codecommit://scott.codecommit@DataBrew-Recipes-Repo
    Cloning into 'DataBrew-Recipes-Repo'...
    remote: Counting objects: 6, done.
    Unpacking objects: 100% (6/6), 2.03 KiB | 138.00 KiB/s, done.
  3. Add a DataBrew recipe into the local repositroy (directory) and commit the change. (either directly on the main branch or merging another branch into the main branch)

Glue DataBrew

  1. Download any recipe either generated out by following Getting started with AWS Glue DataBrew or made by yourself as JSON file.
    image
  2. Move the recipe from the download directory to the local directory for the CodeCommit repository.
    $ mv ${DOWNLOAD_DIRECTORY}/chess-project-recipe.json ${CODECOMMIT_LOCAL_DIRECTORY}/
  3. Commit the change to a branch with a name you prefer.
    $ cd ${{CODECOMMIT_LOCAL_DIRECTORY}}
    $ git checkout -b add-recipe main
    $ git add .
    $ git commit -m "first recipe"
    $ git push --set-upstream origin add-recipe
  4. Merge the branch into the main branch. Just go to the AWS CodeCommit web console to do the merge as its process is purely the same as you've already done thousands of times on Github but only with different UIs.

How Successful Commits Look Like

  1. In the infrastructure account, the status of the CodePipeline DataBrew pipeline should be similar as the following:
    image
  2. In the pre-production account with the same region as where the CICD pipeline is deployed at the infrastructue account, you'll see this.
    image
  3. In the production account with the same region as where the CICD pipeline is deployed at the infrastructue account, you'll see this.
    image
2.0.300

1 day ago

2.0.299

2 days ago

2.0.298

3 days ago

2.0.297

4 days ago

2.0.296

5 days ago

2.0.295

6 days ago

2.0.294

7 days ago

2.0.293

8 days ago

2.0.292

9 days ago

2.0.291

10 days ago

2.0.290

7 months ago

2.0.279

8 months ago

2.0.278

8 months ago

2.0.277

8 months ago

2.0.276

8 months ago

2.0.275

8 months ago

2.0.274

8 months ago

2.0.273

8 months ago

2.0.272

8 months ago

2.0.271

8 months ago

2.0.270

8 months ago

2.0.289

7 months ago

2.0.288

7 months ago

2.0.287

7 months ago

2.0.286

7 months ago

2.0.285

7 months ago

2.0.284

7 months ago

2.0.282

8 months ago

2.0.281

8 months ago

2.0.280

8 months ago

2.0.259

8 months ago

2.0.258

8 months ago

2.0.257

8 months ago

2.0.256

8 months ago

2.0.255

8 months ago

2.0.254

9 months ago

2.0.253

9 months ago

2.0.252

9 months ago

2.0.251

9 months ago

2.0.250

9 months ago

2.0.269

8 months ago

2.0.268

8 months ago

2.0.267

8 months ago

2.0.266

8 months ago

2.0.265

8 months ago

2.0.264

8 months ago

2.0.263

8 months ago

2.0.262

8 months ago

2.0.261

8 months ago

2.0.260

8 months ago

2.0.239

9 months ago

2.0.238

9 months ago

2.0.237

9 months ago

2.0.236

9 months ago

2.0.235

9 months ago

2.0.234

9 months ago

2.0.233

9 months ago

2.0.232

9 months ago

2.0.231

9 months ago

2.0.230

9 months ago

2.0.249

9 months ago

2.0.248

9 months ago

2.0.247

9 months ago

2.0.246

9 months ago

2.0.245

9 months ago

2.0.244

9 months ago

2.0.243

9 months ago

2.0.242

9 months ago

2.0.241

9 months ago

2.0.240

9 months ago

2.0.209

10 months ago

2.0.208

10 months ago

2.0.218

10 months ago

2.0.217

10 months ago

2.0.216

10 months ago

2.0.215

10 months ago

2.0.214

10 months ago

2.0.213

10 months ago

2.0.212

10 months ago

2.0.211

10 months ago

2.0.210

10 months ago

2.0.219

10 months ago

2.0.229

9 months ago

2.0.228

9 months ago

2.0.227

9 months ago

2.0.226

9 months ago

2.0.225

9 months ago

2.0.224

10 months ago

2.0.223

10 months ago

2.0.222

10 months ago

2.0.221

10 months ago

2.0.220

10 months ago

2.0.207

10 months ago

2.0.206

10 months ago

2.0.205

10 months ago

2.0.204

10 months ago

2.0.203

10 months ago

2.0.202

10 months ago

2.0.201

10 months ago

2.0.199

10 months ago

2.0.198

10 months ago

2.0.197

10 months ago

2.0.196

10 months ago

2.0.195

10 months ago

2.0.200

10 months ago

2.0.191

11 months ago

2.0.194

10 months ago

2.0.193

11 months ago

2.0.192

11 months ago

2.0.190

11 months ago

2.0.189

11 months ago

2.0.188

11 months ago

2.0.187

11 months ago

2.0.179

11 months ago

2.0.178

11 months ago

2.0.177

11 months ago

2.0.176

11 months ago

2.0.175

11 months ago

2.0.174

11 months ago

2.0.173

11 months ago

2.0.180

11 months ago

2.0.186

11 months ago

2.0.185

11 months ago

2.0.184

11 months ago

2.0.183

11 months ago

2.0.182

11 months ago

2.0.181

11 months ago

2.0.172

11 months ago

2.0.171

11 months ago

2.0.170

11 months ago

2.0.159

12 months ago

2.0.158

12 months ago

2.0.157

12 months ago

2.0.156

12 months ago

2.0.155

12 months ago

2.0.154

12 months ago

2.0.153

12 months ago

2.0.152

12 months ago

2.0.151

12 months ago

2.0.150

12 months ago

2.0.169

11 months ago

2.0.168

11 months ago

2.0.167

11 months ago

2.0.166

11 months ago

2.0.165

11 months ago

2.0.164

11 months ago

2.0.163

12 months ago

2.0.162

12 months ago

2.0.161

12 months ago

2.0.160

12 months ago

2.0.149

12 months ago

2.0.148

12 months ago

2.0.147

12 months ago

2.0.139

1 year ago

2.0.138

1 year ago

2.0.137

1 year ago

2.0.136

1 year ago

2.0.135

1 year ago

2.0.134

1 year ago

2.0.133

1 year ago

2.0.132

1 year ago

2.0.131

1 year ago

2.0.130

1 year ago

2.0.146

1 year ago

2.0.145

1 year ago

2.0.144

1 year ago

2.0.143

1 year ago

2.0.142

1 year ago

2.0.141

1 year ago

2.0.140

1 year ago

2.0.128

1 year ago

2.0.127

1 year ago

2.0.126

1 year ago

2.0.125

1 year ago

2.0.124

1 year ago

2.0.123

1 year ago

2.0.122

1 year ago

2.0.121

1 year ago

2.0.109

1 year ago

2.0.119

1 year ago

2.0.118

1 year ago

2.0.117

1 year ago

2.0.116

1 year ago

2.0.115

1 year ago

2.0.114

1 year ago

2.0.113

1 year ago

2.0.112

1 year ago

2.0.111

1 year ago

2.0.110

1 year ago

2.0.120

1 year ago

2.0.108

1 year ago

2.0.107

1 year ago

2.0.106

2 years ago

2.0.105

2 years ago

2.0.104

2 years ago

2.0.88

2 years ago

2.0.103

2 years ago

2.0.89

2 years ago

2.0.102

2 years ago

2.0.86

2 years ago

2.0.101

2 years ago

2.0.87

2 years ago

2.0.100

2 years ago

2.0.84

2 years ago

2.0.85

2 years ago

2.0.83

2 years ago

2.0.99

2 years ago

2.0.97

2 years ago

2.0.98

2 years ago

2.0.95

2 years ago

2.0.96

2 years ago

2.0.93

2 years ago

2.0.94

2 years ago

2.0.91

2 years ago

2.0.92

2 years ago

2.0.90

2 years ago

2.0.28

2 years ago

2.0.29

2 years ago

2.0.37

2 years ago

2.0.38

2 years ago

2.0.35

2 years ago

2.0.36

2 years ago

2.0.33

2 years ago

2.0.34

2 years ago

2.0.31

2 years ago

2.0.9

2 years ago

2.0.32

2 years ago

2.0.8

2 years ago

2.0.30

2 years ago

2.0.39

2 years ago

2.0.48

2 years ago

2.0.49

2 years ago

2.0.46

2 years ago

2.0.47

2 years ago

2.0.44

2 years ago

2.0.45

2 years ago

2.0.42

2 years ago

2.0.43

2 years ago

2.0.40

2 years ago

2.0.41

2 years ago

2.0.59

2 years ago

2.0.57

2 years ago

2.0.58

2 years ago

2.0.55

2 years ago

2.0.56

2 years ago

2.0.53

2 years ago

2.0.54

2 years ago

2.0.51

2 years ago

2.0.52

2 years ago

2.0.50

2 years ago

2.0.68

2 years ago

2.0.69

2 years ago

2.0.66

2 years ago

2.0.67

2 years ago

2.0.64

2 years ago

2.0.65

2 years ago

2.0.62

2 years ago

2.0.63

2 years ago

2.0.60

2 years ago

2.0.61

2 years ago

2.0.79

2 years ago

2.0.77

2 years ago

2.0.78

2 years ago

2.0.75

2 years ago

2.0.76

2 years ago

2.0.73

2 years ago

2.0.74

2 years ago

2.0.71

2 years ago

2.0.72

2 years ago

2.0.70

2 years ago

2.0.82

2 years ago

2.0.80

2 years ago

2.0.81

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.26

2 years ago

2.0.27

2 years ago

2.0.24

2 years ago

2.0.25

2 years ago

2.0.22

2 years ago

2.0.23

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.1.39

2 years ago

0.1.37

3 years ago

0.1.38

3 years ago

0.1.36

3 years ago

0.1.35

3 years ago

0.1.34

3 years ago

0.1.32

3 years ago

0.1.33

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.29

3 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.26

3 years ago

0.1.25

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.21

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago