Skip to content

Instantly share code, notes, and snippets.

@arianacosta
Last active October 18, 2019 22:33
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/bc7e0f465b7a772420e6cfac3884dd19 to your computer and use it in GitHub Desktop.
Save arianacosta/bc7e0f465b7a772420e6cfac3884dd19 to your computer and use it in GitHub Desktop.
Uses TS interfaces to create a request and get a response from Lambdas
import { Lambda } from 'aws-sdk'
import { GetGreetingRequest, GetGreetingResponse } from './GetGreetingLambda.ts';
(async () => {
const lambda = new Lambda({
apiVersion: '2015-03-31',
region: 'us-east-1',
});
const request: GetGreetingRequest = { // TS checks the Request properties
firstName: 'Arian',
lastName: 'Acosta',
isFormal: false,
};
const params = {
FunctionName: "LAMBDA_ARN",
Payload: JSON.stringify(request),
};
const { Payload } = await lambda.invoke(params).promise();
// Asserting the parsed object as GetGreetingResponse
const response = JSON.parse(Payload as string) as GetGreetingResponse;
console.log(response.greeting); // TS autocompletes .greeting !
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment