This pattern creates a Kinesis Data Stream that is added as an event source to AWS Lambda function.
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/kinesis-lambda-cdk-python?ref=search
Important: This application uses various AWS services and there are costs associated with these services after the Free Tier usage. Please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS Cloud Development Kit (AWS CDK) (AWS CDK >= 2.1.0) installed
- Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/serverless-patterns
- Change directory to the pattern directory:
cd serverless-patterns/kinesis-lambda-py-cdk
- Create a virtual environment for Python:
python3 -m venv .venv
- Activate the virtual environment :
Linux : source .venv/bin/activate Windows : .venv\Scripts\activate.bat
- Install the Python required dependencies:
pip install -r requirements.txt
- Review the CloudFormation template the cdk generates for you stack using the following AWS CDK CLI command:
cdk synth
- From the command line, use AWS CDK to deploy the AWS resources for the serverless application as specified in the app.py file:
cdk deploy
- Note the outputs from the CDK deployment process. These contain the API Gateway ID which is used for testing.
This pattern creates a Kinsesis Data stream and a Lambda function. The data stream is then added as an event source which can trigger the Lambda function.
From the command line, run the following command to send a single data record to the Kinesis data stream. Note that you must edit the <stream_arn> with the Kinesis data stream ARN that is deployed which will be provided in the stack deployment outputs.
aws kinesis put-record --stream-arn <stream_arn> --partition-key 123 --data testdata
Run the given command to delete the resources that were created. It might take some time for the CloudFormation stack to get deleted.
cdk destroy
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0