npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdk-stepfunctions-redshift

v1.123.0

Published

A JSII construct lib to build AWS Serverless infrastructure to orchestrate Redshift using AWS stepfunctions.

Downloads

178

Readme

Welcome to the cdk-stepfunctions-redshift project!

cdk-stepfunctions-redshift provides SfnRedshiftTasker which is a JSII construct library to build AWS Serverless infrastructure to implement a callback pattern for Amazon Redshift statements.

The SfnRedshiftTasker construct will take details of a Redshift target (clustername, database name & username) and the resulting object will have a lambdaFunction property which will provide the interface to run statements against that Redshift target with callback functionality.

The current solution supports implementing 2 callback patterns:

Behind the scenes

When you use a SfnRedshiftTasker in your stack you will get:

  • A Lambda function for invoking tasks on the Amazon Redshift cluster
  • A DDB Table to track ongoing-executions
  • An Event rule to monitor Amazon Redshift Data API completion events and route them to SQS
  • An SQS queue to receive above mentioned Amazon Redshift Data API completion events
  • A Lambda function to process API Completions events (by default same function as the one above)
  • A KMS key which encrypts data at rest.

This allows to easily create step-function tasks which execute a SQL command and will only complete once Amazon Redshift finishes executing the corresponding statement.

How it works

Serverless infrastructure will be spawn up for a specific (cluster, user, database). A Lambda function will be provided which allows invoking statements as this user. States can then be used to do a seemingly synchronous invocation of a Amazon Redshift statement allowing your statemachines to have a simpler definition (see Example definition for an example state).

Example flow (for step function)

alt text

  1. A step-function step triggers the Lambda function provided by the construct. The step function step follows a structure for its invocation payload which includes designated fields (following the API of the invoker function)

  2. The Lambda function will generate a unique ID based on the execution ARN and register the SQL invocation in a DynamoDB state table.

  3. The lambda function then starts the statement using the Amazon Redshift data API using the Unique ID as statement name and requesting events for state changes.

  4. As a result of step 3 Amazon Redshift executes the statement. Once that statement completes it emits an event. Our building blocks have put in place a Cloudwatch Rule to monitor these events.

  5. The event gets placed into an SQS queue

  6. This SQS queue is monitored by a Lambda function (could be the same as the previous one).

  7. The Lambda function will check whether the finished query is related to a step function invocation in order to retrieve the task token of the step.

  8. If it is then it will do a succeed/fail callback to the step-function step (using the task token) depending on success/failure of the SQL statement.

  9. It will mark the invocation as processed in the state table.

How to use

This is a construct so you can use it from a CDK Stack. An example stack can be found at integ.default.ts . That stack sets up an Amazon Redshift cluster, the SfnRedshiftTasker infra and some state machines that use the functionality. It can be launched by compiling the code (which creates a lib directory) and deploying the CDK app: yarn compile && npx cdk --app ./lib/integ.default.js deploy

Considerations

When using this approach do keep in mind the considerations of the Amazon Redshift Data API.

These shouldn't be blockers:

  • If query result is too big consider using UNLOAD rather than SELECT.
  • If the statement size is too big consider splitting up the statement in multiple statements. For example by defining and utilizing views or encapsulating the logic in a stored procedure.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.