Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Last active November 30, 2022 06:22
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save alexcasalboni/124a096cc94a6156b43b99856937cebb to your computer and use it in GitHub Desktop.
Save alexcasalboni/124a096cc94a6156b43b99856937cebb to your computer and use it in GitHub Desktop.
Bridge Function between Kinesis Streams and Step Functions

Bridge Function between Kinesis Streams and Step Functions

For each record read from the Kinesis Stream, a StepFunction state machine will be executed asynchronously.

Required Environment Variables

  • region: the AWS region where your StepFunction state machine is defined.
  • stateMachineArn: the ARN of the StepFunction state machine you want to execute.

Notes

  • You have to add an updated version of boto3 to your deployment package.
  • You will need a longer timeout, depending on the size of your Kinesis Stream batch.
  • You can connect multiple Kinesis Streams to the same Bridge Function, as long as the state machine is the same.
import os, base64, boto3
sf = boto3.client("stepfunctions", os.environ['region'])
def lambda_handler(event, context):
for record in event['Records']:
payload = base64.b64decode(record['kinesis']['data'])
sf.start_execution(
stateMachineArn=os.environ['stateMachineArn'],
input=payload,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment