Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDK generating empty targets for CfnCrawler

Tags:

aws-cdk

I'm using CDK Python API to define a Glue crawler, however, the CDK generated template contains empty 'Targets' block in the Crawler resource.

I've not been able to find an example to emulate. I've tried varying the definition of the targets object, but the object definition seems to be ignored by CDK.

from aws_cdk import cdk

BUCKET='poc-1-bucket43879c71-5uabw2rni0cp'

class PocStack(cdk.Stack):

    def __init__(self, app: cdk.App, id: str, **kwargs) -> None:
        super().__init__(app, id)

        from aws_cdk import (
            aws_iam as iam,
            aws_glue as glue,
            cdk
        )

        glue_role = iam.Role(
            self, 'glue_role',
            assumed_by=iam.ServicePrincipal('glue.amazonaws.com'),
            managed_policy_arns=['arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole']
        )

        glue_crawler = glue.CfnCrawler(
            self, 'glue_crawler',
            database_name='db',
            role=glue_role.role_arn,
            targets={"S3Targets": [{"Path": f'{BUCKET}/path/'}]},
        )

I expect the generated template to contain a valid 'targets' block with a single S3Target. However, cdk synth outputs a template with empty Targets in the AWS::Glue::Crawler resource:

  gluecrawler:
    Type: AWS::Glue::Crawler
    Properties:
      DatabaseName: db
      Role:
        Fn::GetAtt:
          - glueroleFCCAEB57
          - Arn
      Targets: {}
like image 265
Bob Strahan Avatar asked Jan 25 '26 15:01

Bob Strahan


1 Answers

Resolved, thanks to a clever colleague! Changing "S3Targets" to "s3Targets", and "Path" to "path" resolved the issue. See below.

Hi Bob,

When I use typescript, the following works for me:

new glue.CfnCrawler(this, 'glue_crawler', {
      databaseName: 'db',
      role: glue_role.roleArn,
      targets: {
        s3Targets: [{ path: "path" }]
      }
    }

When I used Python, the following appears working too:

glue_crawler = glue.CfnCrawler(
            self, 'glue_crawler',
            database_name='db',
            role=glue_role.role_arn,
            targets={
                "s3Targets": [{ "path": f'{BUCKET}/path/'}]
            },
        )

In Typescript, TargetsProperty is an interface with s3Targets as a property. And in s3Targets, path is a property as well. I guess during the JSII transformation, it forces us to use the same names in Python instead of the initial CFN resource names.

like image 126
Bob Strahan Avatar answered Jan 29 '26 14:01

Bob Strahan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!