Is the treatment of an Observable distinct in Lambda compared to a Promise?

We have integrated the NestJS CQRS package into our application, which enables us to create 'sagas' through the generation of RxJS Observables that trigger various background tasks.

An issue surfaced when deploying the application on AWS Lambda - the function completes before the background tasks are finished.

Is there a different treatment of an Observable in Lambda compared to a Promise?

@Saga()
aggregateCreated = (events$: Observable<any>): Observable<AggregateCommand> => {
        return events$.pipe(
            ofType(AggregateCreatedEvent),
            map(async (event: AggregateCreatedEvent) => {

                const result = this.queueService.sendMessage(
                    "http://XXXXXXX", { test: "MessageContent });

                await Promise.all([result]);
                return;
            }),
            flatMap(c => c)
        );
    }

Answer №1

When it comes to AWS Lambda functions, returning an Observable seems to be uncharted territory based on existing documentation. The difference between the APIs of an Observable and a Promise is quite significant.


Considering the flow of a @nestjs/cqrs Saga that outputs an Observable of a command, it raises questions about the feasibility of returning such Observables or even Promises within a @Saga in conjunction with AWS Lambda functions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine if two arrays are equal using Jest

I have a method in the test.ts file: public async listComponentsDiffer(lastTag: string, workDir: string): Promise<any[]> This method returns an array with data like this: [{ components: "toto", newVersion: "2", oldVersion: "1" }] I am attempting ...

Make TextField with type number forcibly show dot as decimal separator

I am currently utilizing the material-ui library to display a TextField component in my react application. Strangely, all instances of <TextField type="number /> are displaying decimal separators as commas (,) instead of dots (.), causing confusion f ...

Change prompt-sync from require to import syntax

In my Node project, I have integrated the prompt-sync module. const prompt = require('prompt-sync')(); const result = prompt(message); To maintain consistency in my TypeScript code, I decided to switch from using require to import. In order to ...

When attempting to publish an index.d.ts file using npm, the module is

We are currently in the process of developing an npm package that will serve as the foundation for most of our projects. However, we have encountered some issues that need to be addressed: The index.d.ts file of our base npm package is structured as shown ...

Generating fake data from MongoDB to meet TypeScript requirements in Jest testing

Currently, I am in the process of developing TypeScript interfaces for each model that extends mongoose.Document. import mongoose, { Document } from 'mongoose'; export interface IAccount extends Document { _id: mongoose.Types.ObjectId; name ...

Challenges arise when the $_POST method fails to return a defined index

Although there are similar questions, none have fully addressed my issue. The challenge is to send values via POST to the DB to check if a user exists. Despite using isset and a ternary operator to handle errors, I still encounter persistent PHP errors. I ...

Encountering a Npm ERR! when deploying Angular 6 to Heroku due to missing Start script

I am experiencing an issue with my simple angular 6 app after deploying it to Heroku. When I check the logs using the command heroku logs, I encounter the following error: 2018-07-15T00:45:51.000000+00:00 app[api]: Build succeeded 2018-07-15T00:45:53.9012 ...

What purpose does the question mark (?) serve after a class name when invoking class methods in TypeScript?

One interesting element within my TypeScript code snippet is the presence of the statement row?.delete();. I'm curious about the significance of the question mark in this context. What would be the outcome if 'row' happened to be null? Ap ...

There was an error in the CSS syntax in the production environment due to a missed semicolon

Trying to execute the npm build command "webpack --mode=production --config ./config/webpack.config.prod.js" on our project results in an issue. The issue arises when I include the bootstrap file in my tsx file as shown below. import bs from "../../../../ ...

Typescript error: RequestInit not properly initialized

I'm encountering an issue while using fetch to call an API in a typescript file. The browser is throwing an error stating that const configInit must be initialized, even though I believe it is already. Any suggestions on how to resolve this? Thank you ...

Finding the total of values within an array in Angular 2 and Ionic 2 by utilizing *ngfor

As I work on developing a mobile application using Ionic 2, my current task involves calculating the total allocation sum (Course.allocation) for each year per horse in the database. For instance: Table: Course (Race): [Id_course: 1, allocation: 200, dat ...

Tips for fixing the issue of 'expect(onClick).toHaveBeenCalled();' error

Having trouble testing the click on 2 subcomponents within my React component. Does anyone have a solution? <Container> <Checkbox data-testid='Checkbox' checked={checked} disabled={disabled} onClick={handl ...

Struggling to locate the module 'firebase-admin/app' - Tips for resolving this issue?

While working with Typescript and firebase-admin for firebase cloud functions, I encountered the error message "Cannot find module 'firebase-admin/app'" when compiling the code with TS. Tried solutions: Reinstalling Dependency Deleting node_modu ...

How can I bind the ID property of a child component from a parent component in Angular 2 using @Input?

I have a unique requirement in my parent component where I need to generate a child component with a distinct ID, and then pass this ID into the child component. The purpose of passing the unique ID is for the child component to use it within its template. ...

When using TypeScript in React, the event handler for the onLoad event of an image element cannot locate the properties naturalWidth and naturalHeight

https://i.sstatic.net/vPfkL.png return <img {...props} onLoad={event => { console.log(event.target.naturalWidth) }}/> I am encountering an issue trying to access naturalWidth and naturalHeight in TypeScript React. Unfortunately, TypeScript is ...

Determine the difference between the sizes of two arrays

My current data structure looks like this: [ { name: "A", upvotes: [ "a", "b" ], downvotes: [ "a", "b", "c" ] }, { name: "B", ...

Adding URL path in Angular 7's .ts file

I currently have the following code in my component's HTML file: <button mat-flat-button class="mat-flat-button mat-accent ng-star-inserted" color="accent" (click)="playVideo(video)"> <mat-icon [svgIcon]="video.type === 'external' ...

What are the essential Angular 2 observables for me to utilize?

I have created a form input for conducting searches. Upon user input into the search bar, I want to trigger calls to two separate APIs simultaneously. Here is my current attempt: myInput: new FormControl(); listOne: Observable<string[]>; listTwo: Ob ...

Testing private methods in Angular

I have developed a unique Queue manager that utilizes RxJs observables to execute tasks sequentially. Now, I am facing the challenge of testing this functionality as all the methods I need to test are private. The public interface of my Queue manager cons ...

Unexpected issue occurred in Angular 16 when utilizing less compiler. Error message displayed: "URL token should be closed with a ')'."

I'm having trouble locating the missing parenthesis. It seems like the issue may not be in this file. Any suggestions on how to troubleshoot this? I've already disabled optimization "optimization": false ./src/main.ts - Error: Mod ...