Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-redshift): Tables are always created with a suffix #17064

Closed
gkubes opened this issue Oct 20, 2021 · 4 comments · Fixed by #17213
Closed

(aws-redshift): Tables are always created with a suffix #17064

gkubes opened this issue Oct 20, 2021 · 4 comments · Fixed by #17213
Labels
@aws-cdk/aws-redshift Related to Amazon Redshift bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@gkubes
Copy link

gkubes commented Oct 20, 2021

What is the problem?

When creating a Redshift table using the Table construct the table are always created with a suffix. Looking at the code it appears that this should be an optional behavior.

Reproduction Steps

Create a table

const myTable = new redshift.Table(this, "MyTable", {
    cluster: cluster,
    adminUser: adminSecret,
    databaseName: "MyDb",
    tableName: "s.my_table",
    tableColumns: [
        { name: 'id', dataType: 'numeric(38,0) DISTKEY NOT NULL encode raw' },
        { name: 'request_datetime_utc', dataType: 'timestamp without time zone NULL encode raw' }
    ]
});

and build CDK to generate CFN

"MyTableD7252149": {
  "Type": "Custom::RedshiftDatabaseQuery",
  "Properties": {
    "ServiceToken": {
      "Fn::GetAtt": [
        "MyTableProviderframeworkonEventA4849808",
        "Arn"
      ]
    },
    "handler": "table",
    "clusterName": {
      "Ref": "MyCluster"
    },
    "adminUserArn": {
      "Ref": "AdminSecret"
    },
    "databaseName": "MyDb",
    "tableName": {
      "prefix": "s.my_table",
      "generateSuffix": false
    },
    "tableColumns": [
      {
        "name": "id",
        "dataType": "numeric(38,0) DISTKEY NOT NULL encode raw"
      },
      {
        "name": "request_datetime_utc",
        "dataType": "timestamp without time zone NULL encode raw"
      }
    ]
  },
  "UpdateReplacePolicy": "Retain",
  "DeletionPolicy": "Retain",
  "Metadata": {
    "aws:cdk:path": "MyStack/MyTable/Resource/Resource/Default"
  }
},

Notice that generateSuffix is set to false which would mean that my table should simply have the name s.my_table

What did you expect to happen?

A Redshift table created with the name s.my_table

What actually happened?

A Redshift table created with the name s.my_tabled8a03679

CDK CLI Version

1.126.0

Framework Version

No response

Node.js Version

NodeJS-12.0

OS

Amazon Linux 2012

Language

Typescript

Language Version

No response

Other information

I can see that the generateSuffix: "false" is present in the Lambda Event for the Table creation custom resource

{
    "RequestType": "Create",
    "ServiceToken": "arn:aws:lambda:us-west-2:11111111111111:function:IGTWBRDBInfrastructure-ComplianceDrCidTableProvide-g2VTPfULZtQa",
    "ResponseURL": "https://cloudformation-custom-resource-response-uswest2.s3-us-west-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-west-2%3A1",
    "StackId": "arn:aws:cloudformation:us-west-2:11111111111111:stack/MyStack/9b0abc30-9591-11ea-ba99-067aa3cae1e0",
    "RequestId": "132a420e-5173-4e22-9b96-c04493148172",
    "LogicalResourceId": "MyTableD7252149",
    "ResourceType": "Custom::RedshiftDatabaseQuery",
    "ResourceProperties": {
        "ServiceToken": "arn:aws:lambda:us-west-2:11111111111111:function:MyTableProvide-g2VTPfULZtQa",
        "handler": "table",
        "tableColumns": [
            {
                "dataType": "numeric(38,0) DISTKEY NOT NULL encode raw",
                "name": cid"
            },
            {
                "dataType": "timestamp without time zone NULL encode zstd",
                "name": "request_completed_datetime_utc"
            }
        ],
        "adminUserArn": "arn:aws:secretsmanager:us-west-2:11111111111111:secret:AdminSecret-omYPRk",
        "databaseName": "MyDb",
        "clusterName": "MyCluster",
        "tableName": {
            "prefix": "s.my_table",
            "generateSuffix": "false"
        }
    }
}

however it is a string as opposed to a boolean. As a result props.tableName.generateSuffix ? ${event.RequestId.substring(0, 8)} : '' is evaluated to true instead of false which creates the suffix.

@gkubes gkubes added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 20, 2021
@github-actions github-actions bot added the @aws-cdk/aws-redshift Related to Amazon Redshift label Oct 20, 2021
@gkubes
Copy link
Author

gkubes commented Oct 20, 2021

To work around this I can use an escape hatch to remove the generatePrefix: false attribute

(table.node.findChild("Resource").node.findChild("Resource").node.defaultChild as core.CfnCustomResource).addPropertyDeletionOverride("tableName.generateSuffix");

which results in the following Custom Resource event payload

{
    "RequestType": "Create",
    "ServiceToken": "arn:aws:lambda:us-west-2:11111111111111:function:IGTWBRDBInfrastructure-ComplianceDrCidTableProvide-g2VTPfULZtQa",
    "ResponseURL": "https://cloudformation-custom-resource-response-uswest2.s3-us-west-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-west-2%3A1",
    "StackId": "arn:aws:cloudformation:us-west-2:11111111111111:stack/MyStack/9b0abc30-9591-11ea-ba99-067aa3cae1e0",
    "RequestId": "132a420e-5173-4e22-9b96-c04493148172",
    "LogicalResourceId": "MyTableD7252149",
    "ResourceType": "Custom::RedshiftDatabaseQuery",
    "ResourceProperties": {
        "ServiceToken": "arn:aws:lambda:us-west-2:11111111111111:function:MyTableProvide-g2VTPfULZtQa",
        "handler": "table",
        "tableColumns": [
            {
                "dataType": "numeric(38,0) DISTKEY NOT NULL encode raw",
                "name": cid"
            },
            {
                "dataType": "timestamp without time zone NULL encode zstd",
                "name": "request_completed_datetime_utc"
            }
        ],
        "adminUserArn": "arn:aws:secretsmanager:us-west-2:11111111111111:secret:AdminSecret-omYPRk",
        "databaseName": "MyDb",
        "clusterName": "MyCluster",
        "tableName": {
            "prefix": "s.my_table"
        }
    }
}

Now props.tableName.generateSuffix ? ${event.RequestId.substring(0, 8)} : '' evaluates to ""

@ryparker ryparker added effort/small Small work item – less than a day of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 20, 2021
@iRoachie
Copy link
Contributor

Is it that properties passed in via a custom resource are always converted to strings?

@njlynch
Copy link
Contributor

njlynch commented Oct 28, 2021

Thanks for the detailed bug report!

Agree that the line you linked is the issue in question. Given how this is evaluated, changing the line to check if the generateSuffix is explicitly "true" would probably suffice. Contributions welcome!

@njlynch njlynch added the good first issue Related to contributions. See CONTRIBUTING.md label Oct 28, 2021
@njlynch njlynch removed their assignment Oct 28, 2021
ibrahimcesar added a commit to ibrahimcesar/aws-cdk that referenced this issue Oct 28, 2021
- Check if the generateSuffix is explicitly "true";
- Closes aws#17064
@mergify mergify bot closed this as completed in #17213 Nov 11, 2021
mergify bot pushed a commit that referenced this issue Nov 11, 2021
- Check if the generateSuffix is explicitly 'true';
- Closes #17064


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
- Check if the generateSuffix is explicitly 'true';
- Closes aws#17064


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-redshift Related to Amazon Redshift bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants