Lambda event filtering for DynamoDB - event_name INSERT not working

0

I have DynamoDB set as trigger for my lambda function and the following filter criteria, which is not working.

{"event_name": ["INSERT"]}

I've gone through some examples of properly written filters, but this fails to trigger the lambda. Furthermore, details of my lambda fn is as below. Enter image description here Where does "key" here come from and what does it represent in the Event I am passed to my handler? Here is what my Event looks like;

Event { 
    records: [
        EventRecord { 
            change: StreamRecord { 
                approximate_creation_date_time: ___ 
                keys: {"id": String("___")}, 
                new_image: {
                   ....
                    "valid": Boolean(true), 
                }, 
               ...
            }, 
            ...
            event_name: "INSERT", 
            event_source: Some("aws:dynamodb"), 
            table_name: None 
        }
    ] 
}

Other things bother me like seeing table_name blank because the trigger is specifically being called when data is changed in an specific, existing table.

질문됨 일 년 전1470회 조회
1개 답변
0
수락된 답변

As you can here, the event that your Lambda receives is like this:

{
  "eventID": "c9fbe7d0261a5163fcb6940593e41797",
  "eventName": "INSERT",
  "eventVersion": "1.1",
  "eventSource": "aws:dynamodb",
  "awsRegion": "us-east-2",
  "dynamodb": {
    "ApproximateCreationDateTime": 1664559083.0,
    "Keys": {
      "SK": { "S": "PRODUCT#CHOCOLATE#DARK#1000" },
      "PK": { "S": "COMPANY#1000" }
    },
    "NewImage": {
      "quantity": { "N": "50" },
      "company_id": { "S": "1000" },
      "fabric": { "S": "Florida Chocolates" },
      "price": { "N": "15" },
      "stores": { "N": "5" },
      "product_id": { "S": "1000" },
      "SK": { "S": "PRODUCT#CHOCOLATE#DARK#1000" },
      "PK": { "S": "COMPANY#1000" },
      "state": { "S": "FL" },
      "type": { "S": "" }
    },
    "SequenceNumber": "700000000000888747038",
    "SizeBytes": 174,
    "StreamViewType": "NEW_AND_OLD_IMAGES"
  },
  "eventSourceARN": "arn:aws:dynamodb:us-east-2:111122223333:table/chocolate-table-StreamsSampleDDBTable-LUOI6UXQY7J1/stream/2022-09-30T17:05:53.209"
}

As you only want inserts, your filter pattern should look like this:

{ "eventName": ["INSERT"]}

In your case you specified event_name.

profile pictureAWS
전문가
Uri
답변함 일 년 전
  • Thank you, I tried that earlier, but didn't work and changed it to event_name. BUT it is working now. Does it take some time to reflect the filter pattern?

    Also, I am making a second filter for valid in NewImage. Here is what I've tried; { "dynamodb": { "NewImage": { "valid": { "BOOL": [false] }}}} I've replaced BOOL with B, BOOLEAN, Bool, but none work so far.

    Based off of the scalarAttributeType enum, I'm guessing the correct choice is B, but not sure why it doesn't work.

  • Ok, it's flowing through now, I just needed a bit more patience. 5-10min for others who might find it useful.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠