service:
name: my-service
provider: aws # default for all functions in the service
providers:
aws:
type: aws
region: us-east-1
google:
type: google
region: tokyo
functions:
functionOne:
events:
- http:
path: functionOne
method: GET
functionTwo:
events:
- http:
path: functionOne
method: GET
provider: google
Using external stream/gateway
service:
name: my-service
stream: nordstrom
streams:
nordstrom:
id: gateway.nordstrom.io/s/some/stream
token: ${env:streamToken}
serverless:
id: gateway.serverless.io/s/some/stream
token: ${env:streamToken}
functions:
functionOne:
events: # these events use the service stream
- http:
path: functionOne
method: GET
stream: serverless
functionTwo:
events: # these events use the service stream
- http:
path: functionTwo
method: PUT
stream: nordstrom
service:
name: my-service
providers:
aws:
type: aws
region: us-east-1
google:
type: google
region: tokyo
azure:
type: azure
region: eastus
functions:
functionOne:
provider: aws
events:
- http:
path: functionOne
method: GET
functionTwo:
provider: google
events:
- http:
path: functionTwo
method: PUT
functionThree:
provider: azure
events:
- azure.http: # azure specific http event
path: functionThree
method: POST
service:
name: my-service
service:
name: my-service-users
stream: my-service
streams:
my-service:
id: ${service:my-service.stream}
token: ${env:streamToken}
functions:
createUser:
events:
- http:
path: createUser
method: POST
getUser:
events:
- http:
path: getUser
method: GET
service:
name: my-service-posts
stream: my-service
streams:
my-service:
id: ${service:my-service.stream}
token: ${env:streamToken}
functions:
createPost:
events:
- http:
path: createPost
method: POST
getPost:
events:
- http:
path: getPost
method: GET
Basic emit through emit function
var sdk = require('sdk')
sdk.emit(
{
stream: 'gateway.io/s/ac360/my-service/${env:stage}/comments',
streamToken: '89HA0JAFSLJF09J1A'
}, // config
{
event: 'myBlog.comment.created',
data: {
comment: 'hi'
}
} // event
)
Specify a stream for convenience
const sdk = require('sdk')
const stream = sdk.stream({
stream: 'gateway.io/s/ac360/my-service/${env:stage}/comments',
streamToken: '89HA0JAFSLJF09J1A'
})
stream.emit({
event: 'myBlog.comment.created',
data: {
comment: 'hi'
}
})
stream.emit({
event: 'myBlog.comment.update',
data: {
comment: 'hello'
}
})
- querying/filtering? How do i specify that i only want to subscribe to a subset of events from a stream that match certain criteria?
- security around streams? How do i prevent someone from sending an event type on a stream that they're not allowed to send?
- validation? how do i validate that the publisher is behaving correctly and not sending malformed data?
- why do we need stream tokens?
- is async/sync needed?
auth through distributed public keys
- create service
- generates public/private key pair for service (similar to oauth)
- connect and authorize a service (publisher) to access a stream through the platform
var sdk = require('sdk')
sdk.createSubscription({
streamToken: 'PA019ASFJALSFJA',
event: sdk.query('myapp.payment.received').where('amount').gt(25),
function: {
name: 'checkForFraud'
}
})
This event is handled
stream.emit({
event: 'myapp.payment.received',
data: {
amount: 50
}
})
This event is not
stream.emit({
event: 'myapp.payment.received',
data: {
amount: 10
}
})
config data gets converted to a query
functions:
createUser:
events:
- http:
path: createUser
method: POST
is simply...
var sdk = require('sdk')
sdk.createSubscription({
streamToken: 'PA019ASFJALSFJA',
event: sdk.query('myapp.http.post').where('path').equals('createUser'),
function: {
name: 'createUser'
}
})
other query examples
.where('name.last').equals('Ghost')
.where('age').gt(17).lt(66)
.where('likes').in(['vaporizing', 'talking'])