- JavaScript Cloud Native Development Cookbook
- John Gilbert
- 438字
- 2021-07-16 18:03:33
How it works...
In this recipe, we implement a Command-Line Interface (CLI) program that reads events from the data lake S3 bucket and sends them to a specific AWS Lambda function. When replaying events, we do not re-publish the events because this would broadcast the events to all subscribers. Instead, we want to replay events to a specific function to either repair the specific service or seed a new service.
When executing the program, we provide the name of the data lake bucket and the specific path prefix as arguments. The prefix allows us to replay only a portion of the events, such as a specific month, day, or hour. The program uses functional reactive programming with the Highland.js library. We use a generator function to page through the objects in the bucket and push each object down the stream. Backpressure is a major advantage of this programming approach, as we will discuss in Chapter 8, Designing for Failure. If we retrieved all the data from the bucket in a loop, as we would in the imperative programming style, then we would likely run out of memory and/or overwhelm the Lambda function and receive throttling errors.
Instead, we pull data through the stream. When downstream steps are ready for more work they pull the next piece of data. This triggers the generator function to paginate data from S3 when the program is ready for more data.
When storing events in the data lake bucket, Kinesis Firehose buffers the events until a maximum amount of time is reached or a maximum file size is reached. This buffering maximizes the write performance when saving the events. When transforming the data for these files, we delimited the events with an EOL character. Therefore, when we get a specific file, we leverage the Highland.js split function to stream each row in the file one at a time. The split function also supports backpressure.
For each event, we invoke the function specified in the command-line arguments. These functions are designed to listen for events from a Kinesis stream. Therefore, we must wrap each event in the Kinesis input format that these functions are expecting. This is one reason why we included the Kinesis metadata when saving the events to the data lake in the Creating a data lake recipe. To maximize throughput, we invoke the Lambda asynchronously with the Event InvocationType, provided that the payload size is within the limits. Otherwise, we invoke the Lambda synchronously with the RequestReponse InvocationType. We also leverage the Lambda DryRun feature so that we can see what events might be replayed before actually effecting the change.
- 微電子概論
- 5G XR技術(shù)與應(yīng)用
- iOS應(yīng)用軟件設(shè)計(jì)之道
- 瓷片的誘惑
- 電力通信、信息原理與技術(shù) 上冊:電力通信
- 電子工程師必備:元器件應(yīng)用寶典(強(qiáng)化版)
- 怎樣識讀電子電路圖
- Android商業(yè)軟件開發(fā)全程實(shí)戰(zhàn)
- 現(xiàn)代數(shù)碼產(chǎn)品及其維修技術(shù)
- 通信工程項(xiàng)目管理及監(jiān)理
- 電子技術(shù)及技能訓(xùn)練
- 電路圖快速識讀一讀通
- 電子設(shè)備熱設(shè)計(jì)
- 綠色蜂窩與多跳網(wǎng)絡(luò)設(shè)計(jì)
- 數(shù)字通信同步技術(shù)的MATLAB與FPGA實(shí)現(xiàn)