statusapi-sls

所属分类:FaaS/Serverless
开发工具:GO
文件大小:22KB
下载次数:0
上传日期:2018-03-20 19:43:58
上 传 者sh-1993
说明:  简单状态跟踪器API的无服务器示例
(Serverless example of a simple status tracker API)

文件列表:
Makefile (332, 2018-03-21)
awsctx (0, 2018-03-21)
awsctx\awsctx.go (149, 2018-03-21)
event (0, 2018-03-21)
event\events.go (4212, 2018-03-21)
functions (0, 2018-03-21)
functions\authorizer (0, 2018-03-21)
functions\authorizer\authorizer.go (5039, 2018-03-21)
functions\events (0, 2018-03-21)
functions\events\events_test.go (1899, 2018-03-21)
functions\events\main.go (1919, 2018-03-21)
functions\instances (0, 2018-03-21)
functions\instances\main.go (3767, 2018-03-21)
functions\models (0, 2018-03-21)
functions\models\main.go (5129, 2018-03-21)
functions\models\model_test.go (6335, 2018-03-21)
instance (0, 2018-03-21)
instance\instance.go (1606, 2018-03-21)
internal (0, 2018-03-21)
internal\features (0, 2018-03-21)
internal\features\api (0, 2018-03-21)
internal\features\api\getevents.go (2796, 2018-03-21)
internal\features\api\statusapi.feature (604, 2018-03-21)
internal\features\api\statusapi.go (9431, 2018-03-21)
model (0, 2018-03-21)
model\model.go (4497, 2018-03-21)
models-api.ipynb (3798, 2018-03-21)
serverless.yml (7961, 2018-03-21)

# status api Serverless framework version of a simple status api written using golang. This template is useful for bootstrapping a new project: ``` serverless create -u https://github.com/serverless/serverless-golang/ -p myservice ``` Use the make file to build the binaries needed to deploy. To deploy: ``` serverless deploy --aws-profile ``` Example event payload: ``` {"txn_id":"1a","event_id":"1","step":"Order Received","step_state":"active"} ``` Example model definition: ``` {"name":"model1", "steps":["s1", "s2", "s3"]} ``` Getting an authentication token ``` curl --request POST --url 'https:///oauth/token' --header 'content-type: application/json' --data '{"grant_type":"http://auth0.com/oauth/grant-type/password-realm","username": "the-user-name","password": "the-password", "client_id": "auth0 client id", "client_secret": "client secret", "realm": "Username-Password-Authentication"}' ``` Simple scenario - define a model, post some events, retrieve view of model based on instance state ``` curl -H "Authorization: Bearer XXXX" -XPOST -d '{"name":"model1", "steps":["s1", "s2", "s3"]}' https://ENDPOINT/dev/status/api/v1/models curl -H "Authorization: Bearer XXXX" -XPOST -d '{"txn_id":"1a","event_id":"1","step":"s1","step_state":"completed"}' https://ENDPOINT/dev/status/api/v1/events curl -H "Authorization: Bearer XXXX" -XPOST -d '{"txn_id":"1a","event_id":"2","step":"s2","step_state":"completed"}' https://ENDPOINT/dev/status/api/v1/events curl -H "Authorization: Bearer XXXX" 'https://ENDPOINT/dev/status/api/v1/instances/1a?model=model1' ``` ## Multi-tenant support Note: this is still being fleshed out The basic premise is: 1. Set up user in an [Auth0](https://auth0.com/) domain, and include a tenant attribute in their user_metadata 2. Use a rule to inject the tenant as a claim into the identity token produced by Auth0 3. In a custom authorizer, validate the token, then look up the api key for the tenant. Currently there does not appear to be support for providing the proper settings at the rest api definition in cloud front, so post install the cli has to be used to set api key source from header to authorizer.
# Grab the api id, which is the first component of the expoint
# url, or use the cli
aws apigateway get-rest-apis

# Update the settings using the CLI
aws apigateway update-rest-api --rest-api-id o304m2z79a --patch-operations op=replace,path=/apiKeySource,value=AUTHORIZER
Note that the API must then be redeployed via sls deploy for the API settings update to take effect. So the deploy process is: * Deploy * Configure gateway settings * Redeploy * Seed DDB with tenant keys

近期下载者

相关文件


收藏者