Skip to content

Instantly share code, notes, and snippets.

@arianacosta
Last active February 8, 2020 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arianacosta/00d4e23363d666c22979a6ef41441ad5 to your computer and use it in GitHub Desktop.
Save arianacosta/00d4e23363d666c22979a6ef41441ad5 to your computer and use it in GitHub Desktop.
Lambda that invokes another lambda with DTOs
import { Lambda } from 'aws-sdk';
import { UserDto } from './UserDto';
import { GreetingDto } from './GreetingDto';
const lambda = new Lambda({
apiVersion: '2015-03-31',
region: 'us-east-1',
});
export const handler = async (event: any) => {
const userDto = new UserDto('Arian', 'Acosta', false);
const params = {
FunctionName: "GREETING_LAMBDA_ARN",
Payload: userDto.serialize(),
};
const { Payload } = await lambda.invoke(params).promise();
const greetingDto = GreetingDto.from(Payload);
console.log(greetingDto.greeting); // TS autocompletes .greeting !
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment