@cpmech/az-lambda
v1.0.1 az-lambda
AmaZon AWS Lambda tools
Tools for implementing AWS Lambda functions.
Installation
npm install @cpmech/az-lambda
Example
With query parameters and with json body
Code
import {
IEvent,
IResult,
response,
zeroEvent,
zeroContext,
makeHandlerWithQueryParams,
makeHandlerWithJsonBody,
} from '@cpmech/az-lambda';
interface IParams {
a: string;
b: string;
}
const reference: IParams = {
a: '',
b: '',
};
const func = async (params: IParams): Promise<IResult> =>
response.ok({ message: `hello world ${params.a} ${params.b}` });
const handler1 = makeHandlerWithQueryParams(reference, func);
const handler2 = makeHandlerWithJsonBody(reference, func);
const event1: IEvent = {
...zeroEvent,
queryStringParameters: { a: 'A', b: 'B' },
};
const event2: IEvent = {
...zeroEvent,
body: JSON.stringify({ a: 'AAA', b: 'BBB' }),
};
handler1(event1, zeroContext).then(res => {
console.log(res);
});
handler2(event2, zeroContext).then(res => {
console.log(res);
});
Output
{
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true
},
body: '{"message":"hello world A B"}'
}
{
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true
},
body: '{"message":"hello world AAA BBB"}'
}
npm i @cpmech/[email protected]
Source Code
github.com/cpmech/az-lambda....Metadata
- MIT
- Whatever
- Dorival Pedroso
- released 9/3/2019