Skip to content

Debug Redshift streams ​

This guide will explain some of the steps to debug Redshift streams.

Lambda ​

The first step would be checking the lambda and whether there are and errors in the cloudwatch logs.

Kinesis ​

In AWS check the Kinesis section for error logs. In the navigation menu on the left select Delivery Streams. You'll be presented with a list of all the streams and can select the appropriate one. The errors will be under Destination error logs.

Redshift ​

You can look up the error found in Kinesis using the Amazon Redshift service. This is very useful to look at the table schemas and check for mismatched fields and types.

When you are in Redshift you can select staging under Cluster Overview in the middle of the screen. On the staging cluster page click the Query data button (orange, top right) and select Query in query editor.

You will need to connect to the with the following info (it should autofill after the first login):

  • Database name: staging
  • user: redshiftadmin

Example of a query for the editor: select * from STL_LOAD_ERRORS

The results should give some more information about the error, e.g. what event caused it, what specific field value caused it and what is the error (e.g. Invalid data, Extra column(s) found).

At that point it can be very useful to compare the event that caused the error (that shows up under raw_line when running the error query) with the schema of the Redshift table. Set the left dropdown Select schema to staging and all Redshift tables should be displayed. Clicking on the three dots next to a table name gives the option to Show schema which will include the order of columns and what type of data they expect.

Testing Redshift Streams in lower environments ​

While you can't test DataStreams end to end in a lower environment. You can deploy it and confirm it works from the logs.

To deploy to lower environment ​

Merge your branch with changes to env/* branch.

Find the Stream in the application.yaml under the DDBStreamHandlerFunction comment out:

  • Condition: ShouldDeployE2EDataPipeline.
  • Any FIREHOSE_* variables
  • Any FirehoseCrudPolicy items under Policies.

Within the handler.ts itself, remove any reference to FIREHOSE. Code like logic checking the env vars are set and the use of putDataOnStream function as shown below. Keep the logs logging the data stream items, you'll use them to check its working as expected.

javascript
await putDataOnStream(
  process.env.FIREHOSE_ENGAGEMENTS_INVOICE_SCHEDULE,
  'Engagement Invoice Schedule',
  dsEngagementsInvoiceSchedule,
);

Commit these changes directly to env/* branch (if in LunaAPIs, then deploy).

Do not commit to your changes to your working branch, to avoid any of these changes making there way to main

Checking its working ​

Once deployed, you will be able to read the logs from the DDBStreamHander Lambda function within AWS. Looking for logs like the example below, making sure expected values are there.

2022-10-05T14:43:11.224Z	b7a2be4c-984e-494c-9788-035c0ac1dd38	INFO	[
  'Posting to Engagements Allocations stream : INSERT^pulsar-engagements-table^0^1900/01/01 00:00:00^0fd4abe0-b178-4ae0-8d9f-c66543c43fd0^6c316-5cf5-b6f3-e8fe-6a3053ff5d6^dced961f-ca21-4ae7-94a7-11b43817548d^^^Club Ada^2022-10-27#AM^2022-10-28#PM^2022/10/05 09:04:33^2022/10/05 09:04:33^1664980991223\n'
]

Made with ❤️ by the Luna team