aws-scud v0.3.1
scud
scud
is a Simple Cloud Usable Daemon for serverless RESTful API development.
This library is AWS CDK pattern that takes care about infrastructure boilerplate so that you focuses on development of application logic.
Inspiration
AWS API Gateway and AWS Lambda is a perfect approach for quick prototyping or production development of microservice on Amazon Web Services. Unfortunately, it requires a boilerplate AWS CDK code to bootstrap the development. This library implements a high-order components on top of AWS CDK that hardens the api pattern
The library helps with
- building of lambda functions by integrating "compilation" process within cdk workflows. The following languages are supported:
- Golang
- TypeScript
- integrates validation of OAuth2 Bearer token for each API endpoint
Getting started
The latest version of the library is available at its main
branch. All development, including new features and bug fixes, take place on the main
branch using forking and pull requests as described in contribution guidelines.
npm install --save aws-scud
Example RESTful API
import * as api from '@aws-cdk/aws-apigateway'
import * as lambda from '@aws-cdk/aws-lambda'
import * as scud from 'scud'
import * as pure from 'aws-cdk-pure'
// 1. declare lambda function
const MyFun = (): lambda.FunctionProps =>
scud.handler.Go({
sourceCodePackage: path.join(__dirname, '.'),
sourceCodeLambda: 'myfun',
/* optionally other lambda.FunctionProps */
})
// 2. declare api gateway
const Gateway = (): api.RestApiProps =>
scud.Gateway({
restApiName: 'example',
/* optionally other api.RestApiProps */
})
// 3. assembles RESTful api service from gateway and lambda functions
const service = scud.mkService(Gateway)
.addResource('hello', scud.aws.Lambda(MyFun))
// 4. injects the service to stack
const stack = new cdk.Stack(/* ... */)
pure.join(stack, service)
Please see the RESTful API templates, clone them to draft a new microservice in matter of minutes:
Example RESTful API with Domain Name
Supply custom domain name and ARN of Certificate
const service = scud.mkService(Gateway)
.configRoute53('test.example.com', 'arn:aws:acm:eu-west-1:000000000000:certificate/00000000-0000-0000-0000-000000000000')
Example protect RESTful API with OAuth2
The construct supports integration with AWS Cognito, the integration of AWS API Gateway and AWS Cognito is well depicted by official documentation. The pattern enables deployment of this configuration, just supply ARN of user pool and supply scopes to protect endpoints
const service = scud.mkService(Gateway)
.configOAuth2([ "arn:aws:cognito-idp:..." ])
.addResource('hello', scud.aws.Lambda(MyFun), ["my/scope"])
HowTo Contribute
The project is MIT licensed and accepts contributions via GitHub pull requests:
- Fork it and clone
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
git clone https://github.com/fogfish/scud
cd scud
npm install
npm run build
npm run test
npm run lint