Package Exports
- povery
- povery/dist/main.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (povery) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Povery
Povery is a framework for building things on AWS Lambda with Typescript.
It's heavily opinionated.
You can serve many lambdas as an http server, or you can invoke them locally from the terminal.
Unlike other things like this, it does not want to create lamdas for you (just deploy them, if you wish)
Rules
- Every lambda has a named folder under
lambda
folder. - The entrypoint of the lambda MUST BE
index.ts
file. - Lambdas that serve API Gateway SHOULD BE prefixed with
API_
(e.g.API_Something
) and start with a capital letter. - Lambdas that serve ant other events SHOULD BE prefixed with
EVENT_
(e.g.EVENT_Something
) and start with a capital letter. - API Gateway MUST USE proxy integration to respond to api request.
Install
npm i povery
Api Gateway
This is an example index.ts
to respond to an API Gateway request:
// index.ts
import {povery, controller, api} from 'povery'
@controller
class Service {
@api('GET', /hello')
hello() {
return 'hello world'
}
}
exports.handler = povery.load(Service);
A lambda with this code can also be called in a RPC fashion
// index.ts
const aws = require('aws-sdk');
const lambda = new aws.Lambda();
await lambda.invoke({
FunctionName: 'my-service',
Payload: JSON.stringify({
action: 'hello',
payload: {}
})
}).promise();
AWS Events
This is how to react to AWS events:
// index.ts
import {povery, controller, api} from 'povery'
async function handler(event, context) {
// DO SOMETHING
}
exports.handler = povery.forAwsEvent.load(handler);
JWT Authorization
Povery supports JWT authorization. Authentication must be done on APi Gateway, and the token must be passed to the lambda as a header.
Using withAuth, povery checks for custom:role
claims and matches it with the roles you pass to the decorator.
// index.ts
@controller
class Service {
// only admin can access
@api('GET', /hello')
@acl(['ADMIN'])
hello() {
return 'hello world'
}
}
exports.handler = povery.withAuth().load(Service);
See "Autorization" section in povery.json
for more details.