Skip to content

Commit

Permalink
feat: init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
theburningmonk committed Dec 10, 2023
1 parent 1ccb27a commit f5fe6b5
Show file tree
Hide file tree
Showing 12 changed files with 6,635 additions and 128 deletions.
132 changes: 4 additions & 128 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,130 +1,6 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.serverless
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# hydrate-kinesis-dlq

How to hydrate Kinesis DLQs records
24 changes: 24 additions & 0 deletions examples/ddb-sns-message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestContext": {
"requestId": "76963dc5-2078-46e4-9130-f110338b3058",
"functionArn": "arn:aws:lambda:us-east-1:374852340823:function:hydrate-kinesis-dlq-dev-dynamodb",
"condition": "RetryAttemptsExhausted",
"approximateInvokeCount": 4
},
"responseContext": {
"statusCode": 200,
"executedVersion": "$LATEST",
"functionError": "Unhandled"
},
"version": "1.0",
"timestamp": "2023-12-10T22:59:21.756Z",
"DDBStreamBatchInfo": {
"shardId": "shardId-00000001702248745067-29c36dc7",
"startSequenceNumber": "100000000053490326648",
"endSequenceNumber": "100000000053490326648",
"approximateArrivalOfFirstRecord": "2023-12-10T22:58:57Z",
"approximateArrivalOfLastRecord": "2023-12-10T22:58:57Z",
"batchSize": 1,
"streamArn": "arn:aws:dynamodb:us-east-1:374852340823:table/hydrate-kinesis-dlq-dev-DynamoDBTable-C15SFSF9AYOA/stream/2023-12-10T22:52:22.419"
}
}
24 changes: 24 additions & 0 deletions examples/kinesis-sns-message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestContext": {
"requestId": "cf6fa2a6-48e2-49a6-bc23-7ed2b154b176",
"functionArn": "arn:aws:lambda:us-east-1:374852340823:function:hydrate-kinesis-dlq-dev-kinesis",
"condition": "RetryAttemptsExhausted",
"approximateInvokeCount": 4
},
"responseContext": {
"statusCode": 200,
"executedVersion": "$LATEST",
"functionError": "Unhandled"
},
"version": "1.0",
"timestamp": "2023-12-10T22:06:23.446Z",
"KinesisBatchInfo": {
"shardId": "shardId-000000000000",
"startSequenceNumber": "49647238774018758449143790847474952390342044683891376130",
"endSequenceNumber": "49647238774018758449143790941112301748593148785147772930",
"approximateArrivalOfFirstRecord": "2023-12-10T22:05:59.280Z",
"approximateArrivalOfLastRecord": "2023-12-10T22:06:19.196Z",
"batchSize": 3,
"streamArn": "arn:aws:kinesis:us-east-1:374852340823:stream/hydrate-kinesis-dlq-dev-KinesisStream-nrH7Hk48mKe2"
}
}
3 changes: 3 additions & 0 deletions functions/dynamodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.handler = async (event, context) => {
throw new Error('oops')
}
41 changes: 41 additions & 0 deletions functions/hydrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const {
KinesisClient,
GetShardIteratorCommand,
GetRecordsCommand
} = require("@aws-sdk/client-kinesis")
const kinesisClient = new KinesisClient()

/**
* @param {import('aws-lambda').SNSEvent} event
*/
module.exports.handler = async (event) => {
const snsMessage = JSON.parse(event.Records[0].Sns.Message)
const { shardId, startSequenceNumber, batchSize, streamArn } = snsMessage.KinesisBatchInfo

const streamName = streamArn.split('/')[1]
const getShardIteratorCmd = new GetShardIteratorCommand({
ShardId: shardId,
ShardIteratorType: 'AT_SEQUENCE_NUMBER',
StartingSequenceNumber: startSequenceNumber,
StreamName: streamName
})
const shardIteratorResp = await kinesisClient.send(getShardIteratorCmd)


const getRecordsCmd = new GetRecordsCommand({
ShardIterator: shardIteratorResp.ShardIterator,
Limit: batchSize,
StreamARN: streamArn
})

const getRecordsResp = await kinesisClient.send(getRecordsCmd)
const records = getRecordsResp.Records.map(record => {
const decodedData = Buffer.from(record.Data, 'base64').toString('utf-8')
return decodedData
})

return {
...snsMessage,
KinesisBatch: records
}
}
3 changes: 3 additions & 0 deletions functions/kinesis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.handler = async (event, context) => {
throw new Error('oops')
}
Loading

0 comments on commit f5fe6b5

Please sign in to comment.