title: How to troubleshoot Kinesis Analytics SQL application?
body: <p>I have a KA SQL application deployed via CloudFormation. It is meant to read the data of the kinesis stream then run simple SQL count query and output data to Firehose. Firehose in its turn should write this data to S3. Unfortunately, the data is nowhere to be seen. I am 89% certain that the problem is in the SQL script, but without the logs it is hard to pinpoint the root cause.</p>
  <p>Context:</p>
  <ul>
  <li>KA SQL gets provisioned without &quot;permission/access denied&quot; errors via CloudFormation API.</li>
  <li>KA SQL has CloudWatch logging enabled, which previously has shown configuration errors prior to their fix.</li>
  <li>Firehose has correct permissions to write data to S3. Tested via Firehose UI.</li>
  <li>Unfortunately, at the moment I don't have access to the Kinesis analytics UI as in I lack permissions to create applications through UI.</li>
  </ul>
  <p>Suspicions:</p>
  <ul>
  <li>Rogue quotes in the SQL script located in CFT which was generated via troposphere</li>
  <li>A mistake in the SQL script taken from AWS examples and then slightly modified</li>
  <li>A missing permission somewhere?</li>
  </ul>
  <p>Main question:
  Given there are many moving parts (KA app/Firehose/S3/Kinesis), which you monitor through different CloudWatch metrics and log streams, how do you check if your SQL is simply broken?
  The question might sound silly, but imagine your SQL string getting translated and included into a CFT template via some tool.</p>
  <p>P.S. I attached the CFT just in case a fresh pair of eyes catch something</p>
  <pre><code>{
    &quot;Description&quot;: &quot;Builds KA SQL application&quot;,
    &quot;Resources&quot;: {
      &quot;ApplicationOutput&quot;: {
        &quot;DependsOn&quot;: &quot;KinesisAnalyticsApplication&quot;,
        &quot;Properties&quot;: {
          &quot;ApplicationName&quot;: &quot;sql-poc&quot;,
          &quot;Output&quot;: {
            &quot;DestinationSchema&quot;: {
              &quot;RecordFormatType&quot;: &quot;JSON&quot;
            },
            &quot;KinesisFirehoseOutput&quot;: {
              &quot;ResourceARN&quot;: &quot;arn:aws:firehose:eu-west-1:xxxxxxxxxxx:deliverystream/sql-output&quot;
            },
            &quot;Name&quot;: &quot;DESTINATION_SQL_STREAM&quot;
          }
        },
        &quot;Type&quot;: &quot;AWS::KinesisAnalyticsV2::ApplicationOutput&quot;
      },
      &quot;CloudWatchLoggingOptionForV2KDA&quot;: {
        &quot;DependsOn&quot;: &quot;KinesisAnalyticsApplication&quot;,
        &quot;Properties&quot;: {
          &quot;ApplicationName&quot;: &quot;sql-poc&quot;,
          &quot;CloudWatchLoggingOption&quot;: {
            &quot;LogStreamARN&quot;: &quot;arn:aws:logs:eu-west-1:xxxxxxxxxxx:log-group:/aws/kinesisanalytics/my-log-group:kinesis-analytics-log-stream&quot;
          }
        },
        &quot;Type&quot;: &quot;AWS::KinesisAnalyticsV2::ApplicationCloudWatchLoggingOption&quot;
      },
      &quot;ErrorOutput&quot;: {
        &quot;DependsOn&quot;: &quot;KinesisAnalyticsApplication&quot;,
        &quot;Properties&quot;: {
          &quot;ApplicationName&quot;: &quot;sql-poc&quot;,
          &quot;Output&quot;: {
            &quot;DestinationSchema&quot;: {
              &quot;RecordFormatType&quot;: &quot;JSON&quot;
            },
            &quot;KinesisFirehoseOutput&quot;: {
              &quot;ResourceARN&quot;: &quot;arn:aws:firehose:eu-west-1:xxxxxxxxxx:deliverystream/sql-output&quot;
            },
            &quot;Name&quot;: &quot;error_stream&quot;
          }
        },
        &quot;Type&quot;: &quot;AWS::KinesisAnalyticsV2::ApplicationOutput&quot;
      },
      &quot;KinesisAnalyticsApplication&quot;: {
        &quot;Properties&quot;: {
          &quot;ApplicationConfiguration&quot;: {
            &quot;ApplicationCodeConfiguration&quot;: {
              &quot;CodeContent&quot;: {
                &quot;TextContent&quot;: &quot;CREATE OR REPLACE STREAM \&quot;DESTINATION_SQL_STREAM\&quot; (\&quot;event\&quot; VARCHAR(256),\&quot;count\&quot; INTEGER);CREATE OR REPLACE PUMP \&quot;STREAM_PUMP\&quot; AS INSERT INTO \&quot;DESTINATION_SQL_STREAM\&quot; SELECT STREAM \&quot;event\&quot;, COUNT(*) AS \&quot;count\&quot; FROM \&quot;SOURCE_SQL_STREAM_001\&quot; GROUP BY \&quot;event\&quot;, FLOOR((\&quot;SOURCE_SQL_STREAM_001\&quot;.ROWTIME - TIMESTAMP '1970-01-01 00:00:00') SECOND / 10 TO SECOND);&quot;
              },
              &quot;CodeContentType&quot;: &quot;PLAINTEXT&quot;
            },
            &quot;SqlApplicationConfiguration&quot;: {
              &quot;Inputs&quot;: [
                {
                  &quot;InputSchema&quot;: {
                    &quot;RecordColumns&quot;: [
                      {
                        &quot;Mapping&quot;: &quot;$.event&quot;,
                        &quot;Name&quot;: &quot;event&quot;,
                        &quot;SqlType&quot;: &quot;VARCHAR(256)&quot;
                      }
                    ],
                    &quot;RecordEncoding&quot;: &quot;UTF-8&quot;,
                    &quot;RecordFormat&quot;: {
                      &quot;MappingParameters&quot;: {
                        &quot;JSONMappingParameters&quot;: {
                          &quot;RecordRowPath&quot;: &quot;$&quot;
                        }
                      },
                      &quot;RecordFormatType&quot;: &quot;JSON&quot;
                    }
                  },
                  &quot;KinesisStreamsInput&quot;: {
                    &quot;ResourceARN&quot;: &quot;arn:aws:kinesis:eu-west-1:xxxxxxxxxxx:stream/my-input-kinesis&quot;
                  },
                  &quot;NamePrefix&quot;: &quot;SOURCE_SQL_STREAM&quot;
                }
              ]
            }
          },
          &quot;ApplicationDescription&quot;: &quot;SQL based PoC&quot;,
          &quot;ApplicationName&quot;: &quot;sql-poc&quot;,
          &quot;RuntimeEnvironment&quot;: &quot;SQL-1_0&quot;,
          &quot;ServiceExecutionRole&quot;: &quot;arn:aws:iam::xxxxxxxxxxxx:role/my-iam-role&quot;
        },
        &quot;Type&quot;: &quot;AWS::KinesisAnalyticsV2::Application&quot;
      }
    }
  }
  </code></pre>