Code Monkey home page Code Monkey logo

serverlessland's Introduction

Amazon Kinesis Data Stream trigger AWS Lambda function with CDK

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.

Requirements

Deployment Instructions

  1. 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
    
  2. Change directory to the pattern directory:
    cd serverless-patterns/kinesis-lambda-py-cdk
    
  3. Create a virtual environment for Python:
    python3 -m venv .venv
    
  4. Activate the virtual environment :
    Linux : source .venv/bin/activate
    Windows : .venv\Scripts\activate.bat
    
  5. Install the Python required dependencies:
    pip install -r requirements.txt
    
  6. Review the CloudFormation template the cdk generates for you stack using the following AWS CDK CLI command:
    cdk synth
    
  7. 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
    
  8. Note the outputs from the CDK deployment process. These contain the API Gateway ID which is used for testing.

How it works

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.

Testing

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

Cleanup

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

serverlessland's People

Contributors

sushir-vr avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.