📓
BK Tricks
<- back to the bodik.tech
  • BK Tricks
  • AI\ML
    • Using PostgreSQL with pgvector extension to store and search embeddings
    • JavaScript-based tools
  • Databases
    • PostgreSQL
      • How to Use HOT Updates in PostgreSQL to Boost Your UPDATE Queries
      • Maximizing the Potential of Embeddings with PGvector: A Comprehensive Guide
    • Elasticsearch
      • The impact of Elasticsearch segments on search speed
      • How to aggregate Elasticsearch results by the timestamp on day interval?
      • Mastering Vector Search in Elasticsearch: Mapping Index for KNN
    • Prometheus
      • What is Prometheus and what is it usually used for?
      • How to create a simple Prometheus exporter?
    • Clickhouse
      • How to make a difference of two arrays in ClickHouse?
      • Materialized View that parses JSON or nested JSON from the string field of another table
      • Attach S3 as a storage engine to ClickHouse
      • Table with TTL to S3
      • Partition ClickHouse table based on unique string hash
      • Create a connection to other ClickHouse instance
  • Infrastructure
    • AWS
      • SAM
        • Schema to create a resource of DynamoDB table using SAM
        • Example of enabling streaming functionality of DynamoDB table using SAM resource
        • Schema to create Lambda function resource using SAM
        • Adding environment variables to Lambda function resource using SAM
        • Adding a scheduled timer to start Lambda function resource using SAM
        • Reading stream from DynamoDB by Lambda function declared using SAM
        • Schema to create a resource of SQS queue using SAM
      • CloudFront
        • How to make redirect using Lambda@Edge?
  • Programming
    • JavaScript
      • Convert hexadecimal string to an array of Uint8 values
      • How to decrypt data encoded with NaCl cryptographic algorithm using NodeJS?
      • How to add a property to JavaScript object if it is not empty or null?
  • Tools
    • Kafka
      • Useful tools
      • How to view all of the offsets for some consumer groups in Kafka using CLI?
      • How to set Kafka offsets of a consumer group to a predefined list for all partitions at once?
  • Math
    • Transform the number from one numeric range to another
  • Frontend
    • Useful resources
Powered by GitBook
On this page
  1. Infrastructure
  2. AWS
  3. SAM

Reading stream from DynamoDB by Lambda function declared using SAM

An example of how to read stream from DynamoDB by Lambda function declared using template.yaml of your SAM configuration

YourLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Description: Description of your function
      Runtime: nodejs16.x
      Architectures:
        - x86_64
      Handler: index.handler
      Events:
        Stream:
          Type: DynamoDB
          Properties:
            Stream: !GetAtt YourDynamoDbResourceName.StreamArn
            BatchSize: 1
            MaximumRetryAttempts: 3
            DestinationConfig:
              OnFailure:
                Destination: !GetAtt YourSQSResourceName.Arn
            StartingPosition: TRIM_HORIZON
      MemorySize: 128
      Timeout: 100

With this example, your Lambda function will be executed dynamically when there will be new messages in your DynamoDB stream. In case some error happens, this example includes 3 retries. If none of these was successful Lambda will pass your message to specified SQS queue.

More info on the available properties for the Lambda function creation is here. I use CDK documentation, as I have not found related to SAM resources.

PreviousAdding a scheduled timer to start Lambda function resource using SAMNextSchema to create a resource of SQS queue using SAM

Last updated 2 years ago

Schema to create a resource of DynamoDB table using SAM
Schema to create a resource of SQS queue using SAM
class Function (construct) · AWS CDK
Logo