Last active
February 8, 2020 18:48
-
-
Save arianacosta/00d4e23363d666c22979a6ef41441ad5 to your computer and use it in GitHub Desktop.
Lambda that invokes another lambda with DTOs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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