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-cdk/aws-timestream: CfnScheduledQuery fails to deploy on empty table #22062

Closed
furrycatherder opened this issue Sep 15, 2022 · 2 comments
Closed
Labels
@aws-cdk/aws-timestream Related to the @aws-cdk/aws-timestream package bug This issue is a bug. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed.

Comments

@furrycatherder
Copy link

Describe the bug

My stack includes a CfnScheduledQuery construct that uses a data model mapping. When on-boarding new developers, the construct fails to deploy with the following error:

Error: Resource handler returned message: "line 4:11: Column 'gateway_id' does not exist (Service: AmazonTimestreamQuery; Status Code: 400; Error Code: ValidationException; Request ID: 3J2AVQYLB4GLZYDZQSS6GGBYEA; Proxy: null)" (RequestToken: 5273a8a2-e415-cdb5-9df5-753de764298c, HandlerErrorCode: InvalidRequest)

This is because the source table is empty when it is initially deployed. This presents the annoying problem of having to first seed the source table with dummy items so that the scheduled query can be deployed.

Expected Behavior

The CfnScheduledQuery construct should deploy successfully and report errors later on. There could be an option to disable this validation on construct deployment.

Current Behavior

The construct fails to deploy because the table is empty:

Error: Resource handler returned message: "line 4:11: Column 'gateway_id' does not exist (Service: AmazonTimestreamQuery; Status Code: 400; Error Code: ValidationException; Request ID: 3J2AVQYLB4GLZYDZQSS6GGBYEA; Proxy: null)" (RequestToken: 5273a8a2-e415-cdb5-9df5-753de764298c, HandlerErrorCode: InvalidRequest)

Reproduction Steps

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import * as timestream from "aws-cdk-lib/aws-timestream";
import * as iam from "aws-cdk-lib/aws-iam";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as sns from "aws-cdk-lib/aws-sns";

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

    const db = new timestream.CfnDatabase(this, "Database");
    const sourceTable = new timestream.CfnTable(this, "Table", {
      databaseName: db.ref,
    });

    const role = new iam.Role(this, "ExecutionRole", {
      assumedBy: new iam.ServicePrincipal("timestream.amazonaws.com"),
    });

    const bucket = new s3.Bucket(this, "ErrorsBucket");
    bucket.grantWrite(role);

    const topic = new sns.Topic(this, "Topic");
    topic.grantPublish(role);

    const targetTable = new timestream.CfnTable(this, "ScheduledQueryTable", {
      databaseName: db.ref,
    });

    role.addToPolicy(
      new iam.PolicyStatement({
        actions: ["timestream:DescribeEndpoints"],
        effect: iam.Effect.ALLOW,
        resources: ["*"],
      })
    );
    role.addToPolicy(
      new iam.PolicyStatement({
        actions: ["timestream:Select"],
        effect: iam.Effect.ALLOW,
        resources: [sourceTable.attrArn],
      })
    );
    role.addToPolicy(
      new iam.PolicyStatement({
        actions: ["timestream:WriteRecords"],
        effect: iam.Effect.ALLOW,
        resources: [targetTable.attrArn],
      })
    );

    new timestream.CfnScheduledQuery(this, "ScheduledQuery", {
      queryString: `select gateway_id from "${sourceTable.databaseName}"."${sourceTable.attrName}"`,
      scheduleConfiguration: { scheduleExpression: "rate(1 hour)" },
      errorReportConfiguration: {
        s3Configuration: { bucketName: bucket.bucketName },
      },
      notificationConfiguration: {
        snsConfiguration: {
          topicArn: topic.topicArn,
        },
      },
      scheduledQueryExecutionRoleArn: role.roleArn,
      targetConfiguration: {
        timestreamConfiguration: {
          databaseName: targetTable.databaseName,
          tableName: targetTable.attrName,
          timeColumn: "time",
          measureNameColumn: "measure_name",
          dimensionMappings: [
            { name: "gateway_id", dimensionValueType: "VARCHAR" },
          ],
          mixedMeasureMappings: [
            {
              measureName: "foo",
              measureValueType: "VARCHAR",
              sourceColumn: "bar",
            },
          ],
        },
      },
    });
  }
}
AppStack: creating CloudFormation changeset...
12:32:40 PM | CREATE_FAILED        | AWS::Timestream::ScheduledQuery | ScheduledQuery
Resource handler returned message: "line 1:8: Column 'gateway_id' does not exist (Service: AmazonTimestreamQuery; Status Code: 400; Error Code: ValidationException; Request ID: MPKVW2ZCTHIEEXEEZSAC6IV6FA; Proxy: null)" (Reque
stToken: 9e6cc832-c805-2761-4e5a-7a28b67573e2, HandlerErrorCode: InvalidRequest)

Possible Solution

Allow developers to disable the query validation or ignore it when the table is empty.

Additional Information/Context

No response

CDK CLI Version

2.32.0

Framework Version

No response

Node.js Version

v18.9.0

OS

Linux mochi 5.19.7-zen2-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Mon, 05 Sep 2022 18:33:28 +0000 x86_64 GNU/Linux

Language

Typescript

Language Version

Version 4.7.3

Other information

No response

@furrycatherder furrycatherder added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2022
@github-actions github-actions bot added the @aws-cdk/aws-timestream Related to the @aws-cdk/aws-timestream package label Sep 15, 2022
@peterwoodworth
Copy link
Contributor

Thanks for reporting this @furrycatherder,

I don't think there's anything we can do here however. These constructs you're using are L1 constructs, meaning they are the exact resources CloudFormation offers, so this would be a bug with CloudFormation, or TimeStream as a service itself doesn't support this feature. Could you try submitting a bug report in the CloudFormation Coverage Roadmap if one doesn't exist yet? Thanks 🙂

@peterwoodworth peterwoodworth added needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2022
@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-timestream Related to the @aws-cdk/aws-timestream package bug This issue is a bug. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed.
Projects
None yet
Development

No branches or pull requests

3 participants